﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Resources;
using System.Reflection;
using System.IO;


using Leadtools;
using Leadtools.WinForms;
using Leadtools.ImageProcessing;
using Leadtools.Codecs;
using Leadtools.SpecialEffects;
using Leadtools.ColorConversion;
using Microsoft.Win32;
using System.Configuration;
using System.Collections.Specialized;
using System.Collections;
using System.Xml;
using MINERP.MODEL.FoundationModel;
using MINERP.ComControls;
using MINERP.COM;
using MINERP.BLL.NewProductBigPic;
using MINERP.MODEL.NewProductBigPic;
//using Leadtools.ImageProcessing.Effects;
using System.Diagnostics;
//using LTDImageProcessingEffectsInterop;
using MINERP.NewProductBigPic.Properties;
using System.Drawing.Drawing2D;
using Printing.Common;

using MarkImageDll;
using Microsoft.VisualBasic.Compatibility.VB6;

//using LTDWinFormsCommonDialogsFileInterop;

namespace MINERP.NewProductBigPic
{
    public partial class FrmBigPic : Form
    {
        private int ProductPicCount = 0; //总共生成了多少张大图
        private int PicFormat = 0; //0代表jpg,1代表TIFF
        private bool _isMore = false; //详细信息
        private int BARCODEWIDTH; //条码的宽度，根据字体的大小得到其像素大小
        private int BARCODEHEIGHT = 30; //条码的高度大约2mm
        private Font textBarFont = new Font("3 of 9 Barcode", 50);
        //private Font textBarFont = new Font("Code EAN13", 50);
        private Font textFont = new Font("宋体", 25);
        private Font textSmallFont = new Font("宋体", 25);
        public string _printName = string.Empty;
        public bool IsReboot = false;

        private XmlOperator _xmlOp = new XmlOperator();
        private MainBLL _mainBLL;
        private DelegateUPTLab dlUplbl; //用于更新LABEL的委托
        private DelegateUPTPgro dlUpProgress; //用于更新进度条的委托
        private Graphics gFont;
        string strTempPath = Application.StartupPath + "\\abc.jpg"; //如果是用PS加载ICC时，是用来临时存放到本地的大图的路径
        string RemarkKeysColor = string.Empty;
        MarkImageDll.ClassInterfaceClass mai = null;
        private bool IsAutoCut = false;
        private bool IsPrintPhotoLine = true;
        PSApplition psApp = null;
        private int smallPhotosize = 6; //6inch

        public void test()
        {
            RasterCodecs.Startup();
            RasterCodecs codecs = new RasterCodecs();
            RasterImage smallPicImage = codecs.Load(@"D:\a.jpg");
            RotateCommand rc = new RotateCommand();
            rc.Angle = 90*100;
            rc.FillColor = new RasterColor(255, 255, 255);
            rc.Flags = RotateCommandFlags.Bicubic;

            rc.Run(smallPicImage);
            codecs.Options.Jpeg.Save.QualityFactor = 2;
            codecs.Save(smallPicImage, @"D:\b.jpg", RasterImageFormat.Jpeg, 24);

        }

        public FrmBigPic()
        {
            //test();
            //MessageBox.Show("game over");
            //return;

            //FrmDBManage frmdis = new FrmDBManage();
            //if (DialogResult.OK == frmdis.ShowDialog())
            //{

            InitializeComponent();
            try
            {
                //MessageBox.Show("111222");
                psApp = new PSApplition();
                ///MessageBox.Show("111111");
                mai = new ClassInterfaceClass();
                //MessageBox.Show("222222");
            }
            catch (Exception)
            {

                throw;
            }

            dlUplbl = UPTLab;
            dlUpProgress = UPTPgro;
            //checkBoxBackColorIsGreen.Checked = Settings.Default.BackColor;
            SetSize();
            SetLocation();
            SetTimer();
            try
            {
                _mainBLL = new MainBLL();
            }
            catch (Exception exeException)
            {
                MessageBox.Show("BLL初始化错误");
                throw;
            }
          

            this.cmbPicType.SelectedIndex = 1; //默认生成JPG

            gFont = this.CreateGraphics();
            //float BarCodeSize = 0.0f;
            try
            {
                //BarCodeSize = Convert.ToSingle(txtFontSixe.Text.Trim());
                //textBarFont = new Font("3 of 9 Barcode", Settings.Default.BarCodeSize);
                textBarFont = new Font("C39HrP48DmTt", Settings.Default.BarCodeSize);

            }
            catch (Exception)
            {
                //BarCodeSize = 50;
                //textBarFont = new Font("3 of 9 Barcode", 50);
                textBarFont = new Font("C39HrP48DmTt", 96);

            }
            textFont = new Font("宋体", Settings.Default.FontSize);
            textSmallFont = new Font("宋体", Settings.Default.FontSize/2);
            SizeF sizeF = gFont.MeasureString("3000000000", textBarFont);
            BARCODEWIDTH = ((int) sizeF.Width) + 10; //条码的宽度
            //gFont.Dispose();


            //}
            //Application.Exit();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            IsAutoCut = Properties.Settings.Default.IsAutoCut;
            RemarkKeysColor = Properties.Settings.Default.RemarkKeysColor;
            IsPrintPhotoLine = Properties.Settings.Default.BoolPrintPhotoLine;
            //IsAutoCut = true;
            //if (this.IsReboot)
            //    this.chkIsStart.Checked = true;
            Thread thMake = new Thread(StratWork);
            thMake.IsBackground = true;
            thMake.Start();

            //StratWork();
        }

        #region 生成大图的Help methods

        //得到该图片字体的颜色
        private Color GetFontColorByPhotoInfo(PhotoInfo_ProductBigPic picInfo)
        {

            Color fontColor = Color.Black;

            if (picInfo.Priority >= 10)
            {
                fontColor = Color.Blue;
            }
            else if (picInfo.Priority >= 6)
            {
                fontColor = Color.Red;
            }

            if (picInfo.IsClearBox == 1)
            {
                fontColor = Color.Green;
            }
            //if (!string.IsNullOrEmpty(RemarkKeysColor) && fontColor == Color.Black)
            //{
            //    fontColor = GetRemarkColor(picInfo.PicPath);

            //}
            return fontColor;
        }

        private Color GetRemarkColor(string inPath)
        {
            Color c = Color.FromArgb(0, 0, 0);
            foreach (string keyValues in RemarkKeysColor.Split('#'))
            {

                string[] keyValue = keyValues.Split('@');

                if (string.IsNullOrEmpty(keyValue[0]))
                {
                    continue;
                }
                else
                {
                    if (inPath.Contains("不" + keyValue[0]))
                    {
                        continue;
                    }
                    string[] colorarray = keyValue[1].Split(',');
                    int R = Convert.ToInt16(colorarray[0]);
                    int G = Convert.ToInt16(colorarray[1]);
                    int B = Convert.ToInt16(colorarray[2]);
                    if (inPath.Contains(keyValue[0]))
                    {
                        c = Color.FromArgb(R, G, B);
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

            }
            return c;

        }

        //根据图片信息得到一个中间图，包含条码
        private RasterImage CreateMidImg(PhotoInfo_ProductBigPic picInfo)
        {
            int midPicWidth = 0, midPicHeight = 0; //中间图的宽高
            switch (picInfo.BarCodeStatus)
            {
                case 0: //条码在下方
                    if (picInfo.IsWhirl) //旋转
                    {
                        midPicWidth = picInfo.PixHeight;
                        midPicHeight = picInfo.PixWidth + BARCODEHEIGHT;
                    }
                    else
                    {
                        midPicWidth = picInfo.PixWidth;
                        midPicHeight = picInfo.PixHeight + BARCODEHEIGHT;
                    }
                    break;
                case 1: //条码在右边
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.PixHeight + BARCODEHEIGHT;
                        midPicHeight = picInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.PixWidth + BARCODEHEIGHT;
                        midPicHeight = picInfo.PixHeight;
                    }
                    break;
                case 2: //无条码
                case 3: //无条码
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.PixHeight;
                        midPicHeight = picInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.PixWidth;
                        midPicHeight = picInfo.PixHeight;
                    }
                    break;
            }
            RasterImage midImg = new RasterImage(RasterMemoryFlags.Conventional, midPicWidth, midPicHeight, 24,
                RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);

            FillCommand midfcommand = new FillCommand(); //填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            midfcommand.Run(midImg);
            return midImg;
        }

        private RasterImage CreateMidImg(PhotoInfo_ProductBigPic picInfo, BoardInfo_ProductBigPic board)
        {

            int midPicWidth = 0, midPicHeight = 0; //中间图的宽高
            int tempPicWidth = 0, tempPicHeight = 0; //中间图的宽高
            tempPicWidth = (int) (picInfo.Width*board.BoardBaseInfo.DPI);
            tempPicHeight = (int) (picInfo.Height*board.BoardBaseInfo.DPI);
            switch (picInfo.BarCodeStatus)
            {
                case 1: //条码在下方
                    if (picInfo.IsWhirl) //旋转
                    {
                        midPicWidth = tempPicHeight;
                        midPicHeight = tempPicWidth + BARCODEHEIGHT;
                    }
                    else
                    {
                        midPicWidth = tempPicWidth;
                        midPicHeight = tempPicHeight + BARCODEHEIGHT;
                    }
                    break;
                case 0: //条码在右边
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = tempPicHeight + BARCODEHEIGHT;
                        midPicHeight = tempPicWidth;
                    }
                    else
                    {
                        midPicWidth = tempPicWidth + BARCODEHEIGHT;
                        midPicHeight = tempPicHeight;
                    }
                    break;
                case 2: //无条码
                case 3: //无条码
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = tempPicHeight;
                        midPicHeight = tempPicWidth;
                    }
                    else
                    {
                        midPicWidth = tempPicWidth;
                        midPicHeight = tempPicHeight;
                    }
                    break;
            }
            RasterImage midImg = new RasterImage(RasterMemoryFlags.Conventional, midPicWidth, midPicHeight, 24,
                RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);

            FillCommand midfcommand = new FillCommand(); //填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            midfcommand.Run(midImg);
            return midImg;
        }

        //建立每张待生成的小图片
        private RasterImage CreatePicImg(PhotoInfo_ProductBigPic picInfo, RasterCodecs codes,
            BoardInfo_ProductBigPic board)
        {
            UPTLab("正在加载图片...");
            RasterImage smallPicImage;
            string temFile = Application.StartupPath + "\\tem.tif";
            try
            {
                if (File.Exists(temFile))
                {
                    File.Delete(temFile);
                }
            }
            catch
            {
            }
            string inPath = picInfo.PicPath;
            if (picInfo.IsWhirl)
            {
                if (picInfo.PixWidth >= 10000 || picInfo.PixHeight >= 10000) //大于这个尺寸就用RotateImage进行旋转
                {

                    UPTLab("正在旋转......" + inPath);


                    string temPath = Application.StartupPath + "\\tem.jpg";
                    if (File.Exists(temPath))
                    {
                        File.Delete(temPath);
                    }

                    //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                    //myClass.DoRotate(picInfo.PicPath, temPath, true, 90);
                    psApp.RotatePic(picInfo.PicPath, temPath, 90);

                    smallPicImage = codes.Load(temPath);
                }
                else
                {

                    smallPicImage = codes.Load(picInfo.PicPath);

                    //smallPicImage.c
                    RotateCommand rc = new RotateCommand();
                    rc.Angle = 90*100;
                    rc.FillColor = new RasterColor(255, 255, 255);
                    rc.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                    UPTLab("正在旋转..." + inPath);
                    rc.Run(smallPicImage);
                }
                //旋转后再调整尺寸
                if (smallPicImage.BitsPerPixel == 8) //判断是否灰度
                {
                    ColorResolutionCommand colorRes = new ColorResolutionCommand();
                    colorRes.Mode = ColorResolutionCommandMode.InPlace;
                    colorRes.BitsPerPixel = 24;
                    colorRes.DitheringMethod = RasterDitheringMethod.None;
                    colorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
                    colorRes.Colors = 0;
                    colorRes.Run(smallPicImage);

                }

                UPTLab("正在调整大小...");
                //改变大小,因为在分配打印机时由于四舍五入的原因改变过图像的大小
                SizeCommand command = new SizeCommand();
                //command.Width = picInfo.PixHeight;
                //command.Height = picInfo.PixWidth;
                command.Width = (int) (picInfo.Height*board.BoardBaseInfo.DPI);
                command.Height = (int) (picInfo.Width*board.BoardBaseInfo.DPI);
                command.Flags = RasterSizeFlags.Bicubic;
                command.Run(smallPicImage);
            }
            else
            {

                smallPicImage = codes.Load(picInfo.PicPath);

                //旋转后再调整尺寸
                if (smallPicImage.BitsPerPixel == 8) //判断是否灰度
                {
                    ColorResolutionCommand colorRes = new ColorResolutionCommand();
                    colorRes.Mode = ColorResolutionCommandMode.InPlace;
                    colorRes.BitsPerPixel = 24;
                    colorRes.DitheringMethod = RasterDitheringMethod.None;
                    colorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
                    colorRes.Colors = 0;
                    colorRes.Run(smallPicImage);

                }
                UPTLab("正在调整大小..." + inPath);
                //改变大小,因为在分配打印机时由于四舍五入的原因改变过图像的大小
                SizeCommand command = new SizeCommand();
                ////command.Width = picInfo.PixWidth;
                ////command.Height = picInfo.PixHeight;
                command.Height = (int) (picInfo.Height*board.BoardBaseInfo.DPI);
                command.Width = (int) (picInfo.Width*board.BoardBaseInfo.DPI);
                command.Flags = RasterSizeFlags.Bicubic;

                command.Run(smallPicImage);

            }
            return smallPicImage;
        }

        //建立每张待生成的小图片

        //如果有条码，建立条码图片“包含色块、条码、文字”等信息
        private RasterImage CreateBarCodeImg(PhotoInfo_ProductBigPic picInfo, RasterImage midImageTmp,
            BoardInfo_ProductBigPic board)
        {
            int barCodeImageWidth; //条码图片的宽度,高度是固定的，因为在建图片是“横向建立”
            RasterImage barcodeImageTemp;
            if (picInfo.BarCodeStatus == 0) //左边、右边放条码
            {
                barCodeImageWidth = midImageTmp.Height;
            }
            else
            {
                barCodeImageWidth = midImageTmp.Width;
            }

            barcodeImageTemp = new RasterImage(
                RasterMemoryFlags.Conventional,
                barCodeImageWidth,
                BARCODEHEIGHT,
                1,
                RasterByteOrder.Gray,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);

            //设置条码图片的DPI这样才能扫描时更精确
            FillCommand fcBarcode = new FillCommand();
            fcBarcode.Color = new RasterColor(255, 255, 255);
            barcodeImageTemp.XResolution = board.BoardBaseInfo.DPI;
            barcodeImageTemp.YResolution = board.BoardBaseInfo.DPI;
            fcBarcode.Run(barcodeImageTemp);

            return barcodeImageTemp;
        }

        private RasterImage CreateBarCodeImgH(PhotoInfo_ProductBigPic picInfo, RasterImage midImageTmp,
            BoardInfo_ProductBigPic board)
        {
            int barCodeImageHeight; //条码的高度，图像纵向生成条码的宽是固定的
            RasterImage barcodeImageTemp;
            if (picInfo.BarCodeStatus == 1) //左边、右边放条码
            {
                barCodeImageHeight = midImageTmp.Height;
            }
            else
            {
                barCodeImageHeight = midImageTmp.Width;
            }

            barcodeImageTemp = new RasterImage(
                RasterMemoryFlags.Conventional,
                BARCODEHEIGHT,
                barCodeImageHeight,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);

            //设置条码图片的DPI这样才能扫描时更精确
            FillCommand fcBarcode = new FillCommand();
            fcBarcode.Color = new RasterColor(255, 255, 255);
            barcodeImageTemp.XResolution = board.BoardBaseInfo.DPI;
            barcodeImageTemp.YResolution = board.BoardBaseInfo.DPI;
            fcBarcode.Run(barcodeImageTemp);

            return barcodeImageTemp;
        }

        #endregion

        #region 生成大图

        private delegate void SetPicTypeDl();

        private void SetPicType()
        {
            PicFormat = this.cmbPicType.SelectedIndex - 1;

        }

        //private string _curCutFileFullPath = "";
        private void StratWork()
        {
            //MakeBigPicDelegate dlMakeBigPic = MakeBigPic;
            //IAsyncResult dr;
            BoardInfo_ProductBigPic boardInfo;
            smallPhotosize = Properties.Settings.Default.SmallPhotosize;

            //_cutNoBarcode = DateTransfer.CutNobarCode;

            while (true)
            {
                IsPrintPhotoLine = Properties.Settings.Default.BoolPrintPhotoLine;
                GC.Collect();
                GC.WaitForPendingFinalizers();

                //Thread.Sleep(2000);
                UPTLab("正在获取新的大板信息....");
                int result = 0;
                if (!Settings.Default.TiaoseNo)
                {
                    result = _mainBLL.GetOneBoard(out boardInfo, Settings.Default.MakeBigpictureNo);
                }
                else
                {
                    result = _mainBLL.GetOneBoardAndTiaoseNO(out boardInfo, Settings.Default.MakeBigpictureNo);

                }


                //Thread.Sleep(2000);
                UPTLab("获取成功....");
                if (result == 1)
                {
      
                    BARCODEHEIGHT = boardInfo.BoardBaseInfo.DPI/10;
                    if (boardInfo == null || boardInfo.BoardBaseInfo.BoardId == 0)
                    {
                        UPTLab("boardInfo为NULL或是BOARDID=0");
                        continue;
                    }
                    else
                    {
                        this.Invoke(new SetPicTypeDl(SetPicType));
                        if (boardInfo.BoardBaseInfo.BoardProcudtType == 0)
                        {
                            _cutNoBarcode = false;
                            DateTransfer.TwoCutFlag = false;

                            if (boardInfo.BoardBaseInfo.Printer.IsAutoCut &&
                                Settings.Default.MinAutoCut < boardInfo.ListPhotos.Count)
                            {
                                if (boardInfo.BoardBaseInfo.IsTransverse)
                                {
                                    if (boardInfo.BoardBaseInfo.CutFlagFrontOrBehind == 0)//
                                    {
                                        MakeBigPicH2VCutBeforePic(boardInfo);
                                    }
                                    else
                                    {
                                        MakeBigPicH2VCutAfterPic(boardInfo);
                                    }
                                }
                                else
                                {
                                    if (boardInfo.BoardBaseInfo.CutFlagFrontOrBehind == 0)//
                                    {
                                        MakeBigPicH2HCutBeforePic(boardInfo);
                                    }
                                    else
                                    {
                                        MakeBigPicH2HCutAfterPic(boardInfo);
                                    }
                                }
                               
                            }
                            else
                            {
                                if (boardInfo.BoardBaseInfo.IsTransverse)
                                {
                                    MakeBigPicH(boardInfo); //竖版生成
                                }
                                else
                                {
                                    MakeBigPic(boardInfo); //横版生成
                                }
                            }
                        }
                        else if (boardInfo.BoardBaseInfo.BoardProcudtType == 1)
                        {
                            _cutNoBarcode = true;
                            DateTransfer.TwoCutFlag = true;
                            MakeBigPicH2VCutBeforePicOne(boardInfo);
                        }
                        else
                        {

                        }





                        //if (boardInfo.BoardBaseInfo.IsTransverse)
                        //{
                        //    MakeBigPicH(boardInfo);//竖版生成
                        //}
                        //else
                        //{
                        //    MakeBigPic(boardInfo);//横版生成
                        //}

                        //UPTLab("生成大板成功！");
                    }

                    //dlMakeBigPic.EndInvoke(dr);//等持拼板结束
                }
                else if (result == -4) //没有可用的格子了就暂停30秒后再试
                {
                    UPTLab("没有板可生成或是格子已占满");
                    Thread.Sleep(10*1000);
                }
                else if (result == -5)
                {
                    UPTLab("无法与服务端联接，请检果服务端是否启动?");
                    Thread.Sleep(10*1000);
                }
                else if (result == -2)
                {
                    UPTLab("与服务器连接失败");
                    Thread.Sleep(10*1000);
                }
                else
                {
                    UPTLab("与数据库或是服务器联接异常");
                    Thread.Sleep(10*1000);
                }
            }
        }

        delegate void MakeBigPicDelegate(BoardInfo_ProductBigPic board);

        private void CombinPicAndBarcode(PhotoInfo_ProductBigPic picInfo, ref RasterImage barcodeImageTemp,
            ref RasterImage smallPicImage, ref RasterImage midImageTmp)
        {
            #region 向中间图片mdiImageTemp图贴图片

            CombineFastCommand cfcCommand = new CombineFastCommand();
            Rectangle barCodeRec = new Rectangle(0, 0, 0, 0);
            Rectangle picRec = new Rectangle(0, 0, 0, 0);
            if (!picInfo.IsWhirl)
            {
                if (picInfo.BarCodeStatus == 0) //条码在横向上
                {
                    if (Settings.Default.BarHDirection) //默认在左边
                    {
                        RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
                        rcBarcode.Angle = 90*100;
                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                        rcBarcode.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                        rcBarcode.Run(barcodeImageTemp);
                        barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                        picRec = new Rectangle(BARCODEHEIGHT, 0, smallPicImage.Width, smallPicImage.Height);

                    }
                    else //右边
                    {
                        RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
                        rcBarcode.Angle = 270*100;
                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                        rcBarcode.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                        rcBarcode.Run(barcodeImageTemp);
                        barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                    }
                }
                else if (picInfo.BarCodeStatus == 1) //0:条码放在纵向
                {
                    if (Settings.Default.BarVDirection) //默认在上面
                    {
                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                    }
                    else //下面
                    {
                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width,
                            barcodeImageTemp.Height);
                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                    }

                }
                else if (picInfo.BarCodeStatus == 3)
                {
                    //查看照片是否旋转在原照片底部打印条码横向排版竖向生成条码在照片的左边就是原方向的下方
                    if (picInfo.IsWhirl)
                    {
                        RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
                        rcBarcode.Angle = 90*100;
                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                        rcBarcode.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                        rcBarcode.Run(barcodeImageTemp);

                        barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, smallPicImage.Height);
                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                    }
                    else
                    {
                        barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height,
                            barcodeImageTemp.Width, smallPicImage.Height);
                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                    }
                }
                else
                {
                    barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width,
                        barcodeImageTemp.Height);
                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                }
            }
            else
            {
                if (picInfo.BarCodeStatus == 0) //条码在横向上--看实际照片的话是照片的上下方向 上下方向 默认是上否则是下
                {
                    if (Settings.Default.BarVDirection)
                    {
                        //实际坐标是在后方打条码
                        RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
                        rcBarcode.Angle = 270*100;
                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                        rcBarcode.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                        rcBarcode.Run(barcodeImageTemp);
                        barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);


                    }
                    else
                    {
                        //实际是在左边打条码
                        RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
                        rcBarcode.Angle = 90*100;
                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                        rcBarcode.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                        rcBarcode.Run(barcodeImageTemp);
                        barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                        picRec = new Rectangle(BARCODEHEIGHT, 0, smallPicImage.Width, smallPicImage.Height);
                    }
                }
                else if (picInfo.BarCodeStatus == 1) //0:条码在纵向上 就是上下--看实际照片的话是照片的左右方向 左右方向 默认是左否则是右
                {
                    if (Settings.Default.BarHDirection) //默认在左面
                    {
                        //实际是打在原照片方向的左边但是 是旋转过后照片的上面
                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                    }
                    else //下面
                    {
                        //实际是打在原照片方向的左边但是 是旋转过后照片的下面
                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width,
                            barcodeImageTemp.Height);
                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                    }

                }
                else if (picInfo.BarCodeStatus == 3) //打在照片内部
                {
                    //查看照片是否旋转在原照片底部打印条码横向排版竖向生成条码在照片的左边就是原方向的下方
                    //if (picInfo.IsWhirl)
                    //{
                    //    RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
                    //    rcBarcode.Angle = 90 * 100;
                    //    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                    //    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                    //    rcBarcode.Run(barcodeImageTemp);

                    //    barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, smallPicImage.Height);
                    //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                    //}
                    //else
                    //{
                    //    barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height,
                    //        barcodeImageTemp.Width, smallPicImage.Height);
                    //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                    //}
                }
                else //不打印条码
                {
                    barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width,
                        barcodeImageTemp.Height);
                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                }
            }

            CombineFastCommand cfcBarcode = new CombineFastCommand();
            cfcBarcode.SourcePoint = Point.Empty;
            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfcBarcode.DestinationImage = midImageTmp;



            UPTLab("贴图片");
            //贴图片
            cfcBarcode.DestinationRectangle = picRec;
            cfcBarcode.Run(smallPicImage);


            UPTLab("贴条码");
            //贴条码
            cfcBarcode.DestinationRectangle = barCodeRec;

            cfcBarcode.Run(barcodeImageTemp);

            #endregion
        }

        //private void CombinPicAndBarcode(PhotoInfo_ProductBigPic picInfo, ref  RasterImage barcodeImageTemp, ref RasterImage smallPicImage, ref RasterImage midImageTmp)
        //{
        //    #region 向中间图片mdiImageTemp图贴图片

        //    CombineFastCommand cfcCommand = new CombineFastCommand();
        //    Rectangle barCodeRec = new Rectangle(0, 0, 0, 0);
        //    Rectangle picRec = new Rectangle(0, 0, 0, 0);
        //    if (!picInfo.IsWhirl)
        //    {
        //        if (picInfo.BarCodeStatus == 1) //条码在横向上
        //        {
        //            if (Settings.Default.BarHDirection) //默认在左边
        //            {
        //                RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
        //                rcBarcode.Angle = 90 * 100;
        //                rcBarcode.FillColor = new RasterColor(255, 255, 255);
        //                rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
        //                rcBarcode.Run(barcodeImageTemp);
        //                barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
        //                picRec = new Rectangle(BARCODEHEIGHT, 0, smallPicImage.Width, smallPicImage.Height);

        //            }
        //            else //右边
        //            {
        //                RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
        //                rcBarcode.Angle = 270 * 100;
        //                rcBarcode.FillColor = new RasterColor(255, 255, 255);
        //                rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
        //                rcBarcode.Run(barcodeImageTemp);
        //                barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
        //                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //            }
        //        }
        //        else if (picInfo.BarCodeStatus == 0) //0:条码放在纵向
        //        {
        //            if (Settings.Default.BarVDirection) //默认在上面
        //            {
        //                barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
        //                picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
        //            }
        //            else //下面
        //            {
        //                barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width,
        //                    barcodeImageTemp.Height);
        //                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //            }

        //        }
        //        else if (picInfo.BarCodeStatus == 3)
        //        {
        //            //查看照片是否旋转在原照片底部打印条码横向排版竖向生成条码在照片的左边就是原方向的下方
        //            if (picInfo.IsWhirl)
        //            {
        //                RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
        //                rcBarcode.Angle = 90 * 100;
        //                rcBarcode.FillColor = new RasterColor(255, 255, 255);
        //                rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
        //                rcBarcode.Run(barcodeImageTemp);

        //                barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, smallPicImage.Height);
        //                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //            }
        //            else
        //            {
        //                barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height,
        //                    barcodeImageTemp.Width, smallPicImage.Height);
        //                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //            }
        //        }
        //        else
        //        {
        //            barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width,
        //                barcodeImageTemp.Height);
        //            picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //        }
        //    }
        //    else
        //    {
        //        if (picInfo.BarCodeStatus == 1) //条码在横向上--看实际照片的话是照片的上下方向 上下方向 默认是上否则是下
        //        {
        //            if (Settings.Default.BarVDirection)
        //            {
        //                //实际坐标是在后方打条码
        //                RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
        //                rcBarcode.Angle = 270 * 100;
        //                rcBarcode.FillColor = new RasterColor(255, 255, 255);
        //                rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
        //                rcBarcode.Run(barcodeImageTemp);
        //                barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
        //                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);


        //            }
        //            else
        //            {
        //                //实际是在左边打条码
        //                RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
        //                rcBarcode.Angle = 90 * 100;
        //                rcBarcode.FillColor = new RasterColor(255, 255, 255);
        //                rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
        //                rcBarcode.Run(barcodeImageTemp);
        //                barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
        //                picRec = new Rectangle(BARCODEHEIGHT, 0, smallPicImage.Width, smallPicImage.Height);
        //            }
        //        }
        //        else if (picInfo.BarCodeStatus == 0) //0:条码在纵向上 就是上下--看实际照片的话是照片的左右方向 左右方向 默认是左否则是右
        //        {
        //            if (Settings.Default.BarHDirection) //默认在左面
        //            {
        //                //实际是打在原照片方向的左边但是 是旋转过后照片的上面
        //                barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
        //                picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
        //            }
        //            else //下面
        //            {
        //                //实际是打在原照片方向的左边但是 是旋转过后照片的下面
        //                barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width,
        //                    barcodeImageTemp.Height);
        //                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //            }

        //        }
        //        else if (picInfo.BarCodeStatus == 3)//打在照片内部
        //        {
        //            //查看照片是否旋转在原照片底部打印条码横向排版竖向生成条码在照片的左边就是原方向的下方
        //            //if (picInfo.IsWhirl)
        //            //{
        //            //    RotateCommand rcBarcode = new RotateCommand(); //旋转条码图片               
        //            //    rcBarcode.Angle = 90 * 100;
        //            //    rcBarcode.FillColor = new RasterColor(255, 255, 255);
        //            //    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
        //            //    rcBarcode.Run(barcodeImageTemp);

        //            //    barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, smallPicImage.Height);
        //            //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //            //}
        //            //else
        //            //{
        //            //    barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height,
        //            //        barcodeImageTemp.Width, smallPicImage.Height);
        //            //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //            //}
        //        }
        //        else//不打印条码
        //        {
        //            barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width,
        //                barcodeImageTemp.Height);
        //            picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
        //        }
        //    }

        //    CombineFastCommand cfcBarcode = new CombineFastCommand();
        //    cfcBarcode.SourcePoint = Point.Empty;
        //    cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
        //    cfcBarcode.DestinationImage = midImageTmp;



        //    UPTLab("贴图片");
        //    //贴图片
        //    cfcBarcode.DestinationRectangle = picRec;
        //    cfcBarcode.Run(smallPicImage);


        //    UPTLab("贴条码");
        //    //贴条码
        //    cfcBarcode.DestinationRectangle = barCodeRec;

        //    cfcBarcode.Run(barcodeImageTemp);

        //    #endregion
        //}
        private void MakeBigPic(BoardInfo_ProductBigPic board)
        {
            int i = 0; //当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath; //最终大图的保存路径
            int boardPixWidth = board.BoardBaseInfo.PixWidth; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.PixHeight; //大图的高,相素
            string errText = "";
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();
            if (PicFormat < 0)
            {
                PicFormat = 0;
            }
            //if (PicFormat == 0)
            //{
            //    if (board.BoardBaseInfo.PixHeight / board.BoardBaseInfo.DPI >= 39)//大于39寸时就用TIF出
            //    {
            //        PicFormat = 1;
            //    }
            //    else
            //    {
            //        PicFormat = 0;
            //    }
            //}


            if (PicFormat == 1)
            {
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            //string msg = "正在生成：" + destFileName;
            //this.Invoke(dlUplbl, new string[] { "正在生成：" + destFileName });
            UPTLab("正在生成：" + destFileName);
            //this.Invoke(dlUpProgress, new int[] { 0, 0 });
            UPTPgro(0, 0);
            bool isNeedCut = false;
            if (board.BoardBaseInfo.Printer.IsAutoCut && Settings.Default.MinAutoCut < board.ListPhotos.Count)
                isNeedCut = true;
            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Tiled,
                    boardPixWidth,
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);


                FillCommand fcommand = new FillCommand();
                //if (Settings.Default.BackColor)
                //{
                //    fcommand.Color = new RasterColor(0, 255, 0);
                //}
                //else
                //{
                //    fcommand.Color = new RasterColor(255, 255, 255);
                //}
                fcommand.Color = new RasterColor(Settings.Default.BackColor.R, Settings.Default.BackColor.G,
                    Settings.Default.BackColor.B);
                fcommand.Run(destImage);

                UPTLab("生大大图框架成功");
                foreach (var picInfo in board.ListPhotos)
                {
                    if (picInfo.labelWidth != 0)
                    {
                        BARCODEHEIGHT = picInfo.labelWidth;
                    }
                    UPTLab("正在添加小图:" + picInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上

                        // 根据加急级别以及是否清空等确定字体的颜色

                        if (!File.Exists(picInfo.PicPath))
                        {
                            throw new Exception("文件未找到" + picInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board); //小图片
                        //codecs.Save(smallPicImage, @"D:\\123.jpg", RasterImageFormat.Jpeg, 24);

                        DrowBordLine(ref smallPicImage, Color.Green);
                        RasterImage midImageTmp = CreateMidImg(picInfo, board); //带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");

                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.BarCodeStatus != 2) //有条码
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board); //条码图片的临时图片

                            RasterImage ColorImgBlock = GetProductColorBlock(picInfo.OrderProductId); //色块,根据产品得到不同的色块


                            #region//条码信息有限处理

                            Graphics gBarcode = barcodeImageTemp.CreateGdiPlusGraphics().Graphics; //用来打印条码和文字
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            //int recX = ColorImgBlock.Width + 10, recY = 0;
                            int recX = ColorImgBlock.Width, recY = 0; //当前操作在条码图片上的位置

                            SizeF sizeF = gFont.MeasureString("*" + picInfo.PhotoId.ToString() + "*", textBarFont);
                            //sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution;
                            BARCODEWIDTH = Convert.ToInt32(sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution) + 10;
                                //条码的宽度

                            bool isPrintBarCode = false; //是否要打印条码
                            if (Settings.Default.SmallSizeToPrintBarCode <= 0)
                            {
                                isPrintBarCode = BARCODEWIDTH + 100 <= barcodeImageTemp.Width;
                            }
                            else
                            {
                                isPrintBarCode = barcodeImageTemp.Width >
                                                 Settings.Default.SmallSizeToPrintBarCode*board.BoardBaseInfo.DPI;
                            }

                            //if (BARCODEWIDTH + 100 <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (isPrintBarCode) //如果照片的宽度大于5寸才打印条码,目的是为了显示更多的有用的信息
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIGHT);


                                gBarcode.DrawString("*" + picInfo.PhotoId.ToString() + "*", textBarFont, Brushes.Black,
                                    recX, recY);
                                recX += BARCODEWIDTH;


                            }
                            gBarcode.Dispose();
                            ColorResolutionCommand command =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            command.Run(barcodeImageTemp);

                            #endregion

                            UPTLab("粘贴色块");

                            #region//粘贴色块

                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                barcodeImageTemp.Width,
                                barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd |
                                                CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);

                            #endregion

                            UPTLab("生成条码及文字");

                            #region 文字信息



                            //写其文字信息
                            Graphics gText = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;
                            //recX += 10;
                            Rectangle rcFont = new Rectangle(recX, 0, barcodeImageTemp.Width - recX, BARCODEHEIGHT);

                            string barStr = GetBarCodeStringByCutsom(picInfo, board);
                            if (string.IsNullOrEmpty(barStr))
                            {
                                barStr = picInfo.GridName + @"\P" + //格子号
                                         picInfo.PhotoId + @"\O" + //照片号
                                         picInfo.OrderProductId + @"\" + //产品号
                                         picInfo.Remark + "\\" +
                                         picInfo.OrderProductName + @"\" +
                                         picInfo.ShopName + @"\B" +
                                         board.BoardBaseInfo.BoardId + @"\" +
                                         picInfo.Width.ToString("0.00") + "*" +
                                         picInfo.Height.ToString("0.00") + "(" +
                                         (picInfo.Width*2.54).ToString("0.00") + "*" +
                                         (picInfo.Height*2.54).ToString("0.00") + @")\" +
                                         DateTime.Now.ToString();
                            }
                            barStr = barStr.Trim('\\').Trim().Trim('\\');
                            //barStr = barStr.Substring(barStr.IndexOf("P"));
                            //自使用字号
                            if (smallPhotosize < (float) barcodeImageTemp.Width/barcodeImageTemp.XResolution)
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;

                                gText.DrawString(barStr, textFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            else
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;
                                gText.DrawString(barStr, textSmallFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            ColorResolutionCommand gTextCommandommand =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            gTextCommandommand.Run(barcodeImageTemp);
                            gText.Dispose();
                            ColorImgBlock.Dispose(); //释放色块的资源

                            #endregion

                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombinPicAndBarcode(picInfo, ref barcodeImageTemp, ref smallPicImage, ref midImageTmp);

                            ////                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            //                            Rectangle barCodeRec, picRec;

                            //                            if (picInfo.BarCodeStatus == 0)//条码 L OR R
                            //                            {

                            //                                if (Settings.Default.BarHDirection)//默认 L
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 90 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);

                            //                                    //codecs.Save(barcodeImageTemp, @"D:\123456.jpg", RasterImageFormat.Jpeg, 24);

                            //                                    barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT ,barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(BARCODEHEIGHT, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else// R
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 270 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);
                            //                                    barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                            }
                            //                            else if (picInfo.BarCodeStatus == 1)//条码在 T OR B
                            //                            {
                            //                                if (Settings.Default.BarVDirection)//默认在 T
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else// B
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }

                            //                            }
                            //                            else if (picInfo.BarCodeStatus == 3)
                            //                            {
                            //                                //查看照片是否旋转在原照片底部打印条码横向排版竖向生成条码在照片的左边就是原方向的下方
                            //                                if (picInfo.IsWhirl)
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 90 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);
                            //                                    barCodeRec = new Rectangle(smallPicImage.Width - BARCODEHEIGHT, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                            }
                            //                            else
                            //                            {
                            //                                barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                            }

                            //                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            //                            cfcBarcode.SourcePoint = Point.Empty;
                            //                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            //                            cfcBarcode.DestinationImage = midImageTmp;


                            //                            UPTLab("贴图片");
                            //                            //贴图片
                            //                            cfcBarcode.DestinationRectangle = picRec;
                            //                            cfcBarcode.Run(smallPicImage);

                            ////							codecs.Save(smallPicImage, @"D:\123456.jpg", RasterImageFormat.Jpeg, 24);

                            //                            UPTLab("贴条码");
                            //                            //贴条码
                            //                            cfcBarcode.DestinationRectangle = barCodeRec;

                            //                            cfcBarcode.Run(barcodeImageTemp);




                            //                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片

                            #endregion

                        }
                        else //无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                smallPicImage.Width,
                                smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd |
                                               CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }

                        #endregion

                        UPTLab("给中间图画边框");

                        #region //给中间图画边框

                        if (IsPrintPhotoLine)
                        {
                            DrowBordLine(ref midImageTmp);
                        }
                        //								codecs.Save(midImageTmp, @"D:\123456.jpg", RasterImageFormat.Jpeg, 24);

                        #endregion

                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }


                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                            pointX, //在大图上的坐标
                            pointY,
                            midImageTmp.Width, //长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);



                        if (isNeedCut) //自动裁切模式
                        {

                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointX;
                            photoP.Y = pointY;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;
                            listPhotoInfoForCut.Add(photoP);
                        }

                        UPTLab("将中间图贴在大图上");
                        //将中间图贴在大图上
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();

                        UPTPgro(board.ListPhotos.Count, i++); //进度条
                        //this.Invoke(dlUpProgress, new int[] { board.ListPhotos.Count, ++i });
                        UPTLab("添加小图成功:" + picInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {

                        errText = picInfo.PicPath;
                        throw ex;
                    }

                }
                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;
                //判断目录是否存在
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }


                //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                //{
                //    UPTLab("正在竖向旋转90度...");


                //    RotateCommand rc = new RotateCommand();
                //    rc.Angle = 90 * 100;
                //    rc.FillColor = new RasterColor(255, 255, 255);
                //    rc.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                //    rc.Run(destImage);                
                //}
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;


                if (board.BoardBaseInfo.Sharpen > 0) //如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    Leadtools.ImageProcessing.Effects.SharpenCommand command =
                        new Leadtools.ImageProcessing.Effects.SharpenCommand();
                    command.Sharpness = board.BoardBaseInfo.Sharpen;
                    command.Run(destImage);
                }
                if (isNeedCut) //自动裁切模式要替换最终destImage
                {
                    UPTLab("创建自动裁切信息");
                    string markPath = Application.StartupPath + "\\temBar.bmp";
                    if (File.Exists(markPath))
                    {
                        File.Delete(markPath);
                    }
                    var s =
                        mai.CreateMarkPictureToFile(
                            Convert.ToInt32((double) BoardPixHeight/board.BoardBaseInfo.DPI*2.54*100),
                            board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp",
                            board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());

                    RasterImage smallTop = codecs.Load(markPath);
                    RotateCommand rcMark = new RotateCommand();
                    rcMark.Angle = 270*100;
                    rcMark.FillColor = new RasterColor(255, 255, 255);
                    rcMark.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                    rcMark.Run(smallTop);

                    ///创建大板的条码信息
                    //RasterImage destTempImage = destImage;//先将名称替换掉


                    RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                        destImage.Width + smallTop.Width,
                        destImage.Height,
                        24,
                        RasterByteOrder.Bgr,
                        RasterViewPerspective.BottomLeft,
                        null,
                        IntPtr.Zero,
                        0); //);

                    destTempImage.XResolution = board.BoardBaseInfo.DPI;

                    CombineFastCommand cfctop = new CombineFastCommand();
                    //cfctop.DestinationRectangle = new Rectangle(180, 0, boardPointInfoImage.Width, boardPointInfoImage.Height);
                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                    cfctop.SourcePoint = Point.Empty;
                    cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(smallTop);
                    cfctop.DestinationRectangle = new Rectangle(smallTop.Width, 0, destImage.Width, destImage.Height);
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(destImage);
                    destImage = destTempImage; //重新赋值

                    //写入文件
                    StringBuilder sbWriter = new StringBuilder();
                    sbWriter.AppendLine(
                        (((double) board.BoardBaseInfo.PixHeight/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                        (((double) board.BoardBaseInfo.PixWidth/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                        board.BoardBaseInfo.PrintName);
                    foreach (PhotoPoint pp in listPhotoInfoForCut)
                    {
                        string mmy = (((double) pp.X/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                        string mmX =
                        (((double) (board.BoardBaseInfo.PixHeight - pp.Y - pp.Height)/board.BoardBaseInfo.DPI*2.54*
                          100)).ToString("0");
                        string mmWidth = (((double) pp.Height/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                        string mmheight = (((double) pp.Width/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                        string strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                        sbWriter.AppendLine(strWriter);

                    }
                    //计算裁切尺寸
                    //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                    //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                    //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                    //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                    ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                    string FileName = destFileName.Substring(0, destFileName.LastIndexOf("@")) + ".txt";
                    if (File.Exists(FileName))
                    {
                        File.Delete(FileName);
                    }
                    CommFile.WrtieTextEn(sbWriter, FileName);
                    //_mainBLL.SetBoardAutoCutInfo(board.BoardBaseInfo.BoardId, sbWriter.ToString());

                }

                UPTLab("正在保存大图...");
                //codecs.Save(destImage, @"D:\123456.jpg", RasterImageFormat.Jpeg, 24);
                if (Settings.Default.AddIccByPs) //需要用PS加载ICC
                {
                    if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                    {
                        codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                    }
                    else
                    {
                        codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                    }

                }
                else //用LEADTOOLS加载ICC
                {
                    //处理旋转的问题
                    if (board.BoardBaseInfo.IsTransverse) //竖向的就转90
                    {
                        string tempSrcPath = Application.StartupPath + "\\temBig.jpg";
                        string tempToPath = Application.StartupPath + "\\tem.jpg";
                        UPTLab("正在竖向旋转90度...");
                        if (destImage.Width >= 9000 || destImage.Height >= 9000) //大于这个尺寸就用PS进行旋转
                        {
                            try
                            {
                                File.Delete(tempSrcPath);
                                File.Delete(tempToPath);
                            }
                            catch
                            {
                            }

                            codecs.Save(destImage, tempSrcPath, RasterImageFormat.Jpeg, 24);

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //myClass.DoRotate(tempSrcPath, tempToPath, true, 270);
                            psApp.RotatePic(tempSrcPath, tempToPath, 270);

                            destImage = codecs.Load(tempToPath);
                            File.Delete(tempSrcPath);

                        }
                        else
                        {
                            RotateCommand rc = new RotateCommand();
                            rc.Angle = 270*100;
                            rc.FillColor = new RasterColor(255, 255, 255);
                            rc.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                            rc.Run(destImage);
                        }

                    }

                    switch (PicFormat)
                    {
                        case 0:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }

                    #region//指定转换配置文件(不通过ps加载ICC时用)

                    string colorSpace = Properties.Settings.Default.ColorSpace;
                    bool setColorSpace = Properties.Settings.Default.SetColorSpace;
                    string fname = Application.StartupPath + "\\SetSpaceTem.jpg";

                    int intRatate = 0;
                    if (board.BoardBaseInfo.IsTransverse) //竖向的就转270
                    {
                        intRatate = 270;
                    }
                    string strResult = string.Empty, strPicFormat;
                    if (setColorSpace)
                    {
                        try
                        {
                            File.Delete(Application.StartupPath + "\\SetSpaceTem.jpg");
                        }
                        catch
                        {
                        }
                        codecs.Save(destImage, Application.StartupPath + "\\SetSpaceTem.jpg", RasterImageFormat.Jpeg, 24);
                        //PSICC.ClassIccClass myclass = new PSICC.ClassIccClass();

                        //switch (PicFormat)
                        //{
                        //    case 0: strPicFormat = "JPEG"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref  intRatate);

                        //        break;
                        //    case 1: strPicFormat = "TIFF"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref intRatate);
                        //        break;
                        //}

                        if (strResult == destFileName)
                        {
                            UPTLab("成功转换配置文件:" + colorSpace);
                        }
                        else
                        {
                            //加载ICC失败
                            UPTLab("转换配置文件失败!" + strResult);
                            throw new Exception("转换配置文件失败!" + strResult);
                        }
                    }

                    #endregion

                }



                #region //写入ICC文件

                UPTLab("正在加载ICC文件..." + board.BoardBaseInfo.IccPath);
                if ((File.Exists(board.BoardBaseInfo.IccPath)) && !string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) &&
                    board.BoardBaseInfo.IccPath != @"\\")
                {
                    if (Properties.Settings.Default.AddIccByPs) //需要用PS加载ICC
                    {
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName =
                                board.BoardBaseInfo.IccPath.Substring(board.BoardBaseInfo.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName); //如果以前生成过图片，则删除已生成的
                            }
                            catch
                            {
                            }

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            string strResult = string.Empty, strPicFormat;
                            string strInputIcc = Settings.Default.ColorSpace;
                            //string strInputIcc = "ColorMatch RGB";
                            //string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.BoardBaseInfo.IsTransverse) //竖向的就转90
                                intRatate = -90;

                            //switch (PicFormat)
                            //{
                            //    case 0: strPicFormat = "JPEG"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref  intRatate);

                            //        break;
                            //    case 1: strPicFormat = "TIFF"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                            //        break;
                            //}


                            psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                //加载ICC失败
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件失败!" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath); //删除保存到C盘的零时的图片文件
                            }
                            catch
                            {
                            }
                        }
                    }
                    else //用LEADTOOLS加载ICC
                    {
                        try
                        {
                            IccProfileExtended iccProfile = new IccProfileExtended(board.BoardBaseInfo.IccPath);
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);

                        }
                        catch (Exception ef)
                        {
                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }
                    }
                }

                #endregion

                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0); //进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                _mainBLL.MakeBigPicSusscess(board.BoardBaseInfo.BoardId, destFileName); //生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");
            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                //codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //errText = "生成大图错误"+ex1.Message;
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int) EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }

        private void DrowBordLine(ref RasterImage rstImg)
        {
            //RasterCodecs codecs = new RasterCodecs();
            RasterImage leftLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                1, //+1
                rstImg.Height,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);
            FillCommand fcommandW = new FillCommand();
            fcommandW.Color = new RasterColor(0, 0, 0);
            fcommandW.Run(leftLine);
            RasterImage RightLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                1, //+1
                rstImg.Height,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);

            fcommandW.Color = new RasterColor(0, 0, 0);
            fcommandW.Run(RightLine);
            RasterImage TopLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                rstImg.Width, //+1
                1,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);
            fcommandW.Color = new RasterColor(0, 0, 0);
            fcommandW.Run(TopLine);
            RasterImage BottomLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                rstImg.Width, //+1
                1,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);
            fcommandW.Color = new RasterColor(0, 0, 0);
            fcommandW.Run(BottomLine);
            CombineFastCommand cfcLine = new CombineFastCommand();
            cfcLine.SourcePoint = Point.Empty;
            cfcLine.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfcLine.DestinationImage = rstImg;

            cfcLine.DestinationRectangle = new Rectangle(0, 0, leftLine.Width, leftLine.Height);
            cfcLine.Run(leftLine);

            cfcLine.DestinationRectangle = new Rectangle(rstImg.Width - 1, 0, RightLine.Width, RightLine.Height);
            cfcLine.Run(RightLine);

            cfcLine.DestinationRectangle = new Rectangle(0, 0, TopLine.Width, TopLine.Height);
            cfcLine.Run(TopLine);

            cfcLine.DestinationRectangle = new Rectangle(0, rstImg.Height - 1, BottomLine.Width, BottomLine.Height);
            cfcLine.Run(BottomLine);



        }

        private void DrowBordLine(ref RasterImage rstImg, Color lineColor)
        {
            //RasterCodecs codecs = new RasterCodecs();
            RasterImage leftLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                1, //+1
                rstImg.Height,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);
            FillCommand fcommandW = new FillCommand();
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(leftLine);
            RasterImage RightLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                1, //+1
                rstImg.Height,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);

            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(RightLine);
            RasterImage TopLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                rstImg.Width, //+1
                1,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(TopLine);
            RasterImage BottomLine = new RasterImage(
                RasterMemoryFlags.Conventional,
                rstImg.Width, //+1
                1,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(BottomLine);
            CombineFastCommand cfcLine = new CombineFastCommand();
            cfcLine.SourcePoint = Point.Empty;
            cfcLine.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfcLine.DestinationImage = rstImg;

            cfcLine.DestinationRectangle = new Rectangle(0, 0, leftLine.Width, leftLine.Height);
            cfcLine.Run(leftLine);

            cfcLine.DestinationRectangle = new Rectangle(rstImg.Width - 1, 0, RightLine.Width, RightLine.Height);
            cfcLine.Run(RightLine);

            cfcLine.DestinationRectangle = new Rectangle(0, 0, TopLine.Width, TopLine.Height);
            cfcLine.Run(TopLine);

            cfcLine.DestinationRectangle = new Rectangle(0, rstImg.Height - 1, BottomLine.Width, BottomLine.Height);
            cfcLine.Run(BottomLine);



        }

        /// <summary>
        /// /横版排竖版生成/横版排竖版生成
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH(BoardInfo_ProductBigPic board)
        {
            //var p1 = mai.CreateMarkPictureToFile(7620, 254,@"c:\1234.bmp", "123", "abc");

            int i = 0; //当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath; //最终大图的保存路径
            int boardPixWidth = board.BoardBaseInfo.PixHeight; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.PixWidth; //大图的高,相素
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();
            string errText = "";
            int XExcursion = 0;
            if (PicFormat < 0)
            {
                PicFormat = 0;
            }
            XExcursion = boardPixWidth;
            //if (PicFormat == 0)
            //{
            //    if (board.BoardBaseInfo.PixHeight / board.BoardBaseInfo.DPI >= 39)//大于39寸时就用TIF出
            //    {
            //        PicFormat = 1;
            //    }
            //    else
            //    {
            //        PicFormat = 0;
            //    }
            //}


            if (PicFormat == 1)
            {
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            //string msg = "正在生成：" + destFileName;
            //this.Invoke(dlUplbl, new string[] { "正在生成：" + destFileName });
            UPTLab("正在生成：" + destFileName);
            //this.Invoke(dlUpProgress, new int[] { 0, 0 });
            UPTPgro(0, 0);
            bool isNeedCut = false;
            if (board.BoardBaseInfo.Printer.IsAutoCut && Settings.Default.MinAutoCut < board.ListPhotos.Count)
                isNeedCut = true;
            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Tiled,
                    boardPixWidth,
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                FillCommand fcommand = new FillCommand();
                //if (Settings.Default.BackColor)
                //{
                //    fcommand.Color = new RasterColor(0, 255, 0);
                //}
                //else
                //{
                //    fcommand.Color = new RasterColor(255, 255, 255);
                //}
                fcommand.Color = new RasterColor(Settings.Default.BackColor.R, Settings.Default.BackColor.G,
                    Settings.Default.BackColor.B);
                fcommand.Run(destImage);

                UPTLab("生大大图框架成功");
                foreach (var picInfo in board.ListPhotos)
                {
                    if (picInfo.labelWidth != 0)
                    {
                        BARCODEHEIGHT = picInfo.labelWidth;
                    }
                    int temp = 0;
                    //temp=picInfo.PixHeight;
                    //picInfo.PixHeight = picInfo.PixWidth;
                    //picInfo.PixWidth = temp;


                    //picInfo.IsWhirl = !picInfo.IsWhirl;
                    UPTLab("正在添加小图:" + picInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上

                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.PicPath))
                        {
                            throw new Exception("文件不存在：" + picInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board); //小图片
                        if (IsPrintPhotoLine)
                        {
                            DrowBordLine(ref smallPicImage, Color.Green);
                        }
                        RasterImage midImageTmp = CreateMidImg(picInfo, board); //带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");

                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.BarCodeStatus != 2) //有条码
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board); //条码图片的临时图片

                            RasterImage ColorImgBlock = GetProductColorBlock(picInfo.OrderProductId); //色块,根据产品得到不同的色块


                            #region//条码信息有限处理

                            Graphics gBarcode = barcodeImageTemp.CreateGdiPlusGraphics().Graphics; //用来打印条码和文字
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            //int recX = ColorImgBlock.Width + 10, recY = 0;
                            int recX = ColorImgBlock.Width, recY = 0; //当前操作在条码图片上的位置

                            SizeF sizeF = gFont.MeasureString("*" + picInfo.PhotoId.ToString() + "*", textBarFont);
                            //sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution;
                            BARCODEWIDTH = Convert.ToInt32(sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution) + 10;
                                //条码的宽度

                            bool isPrintBarCode = false; //是否要打印条码
                            if (Settings.Default.SmallSizeToPrintBarCode <= 0)
                            {
                                isPrintBarCode = BARCODEWIDTH + 100 <= barcodeImageTemp.Width;
                            }
                            else
                            {
                                isPrintBarCode = barcodeImageTemp.Width >
                                                 Settings.Default.SmallSizeToPrintBarCode*board.BoardBaseInfo.DPI;
                            }

                            //if (BARCODEWIDTH + 100 <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (isPrintBarCode) //如果照片的宽度大于5寸才打印条码,目的是为了显示更多的有用的信息
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIGHT);


                                gBarcode.DrawString("*" + picInfo.PhotoId.ToString() + "*", textBarFont, Brushes.Black,
                                    recX, recY);
                                recX += BARCODEWIDTH;


                            }
                            gBarcode.Dispose();
                            ColorResolutionCommand command =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            command.Run(barcodeImageTemp);

                            #endregion

                            UPTLab("粘贴色块");

                            #region//粘贴色块

                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                barcodeImageTemp.Width,
                                barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd |
                                                CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);

                            #endregion

                            UPTLab("生成条码及文字");

                            #region 文字信息



                            //写其文字信息
                            Graphics gText = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;
                            //recX += 10;
                            Rectangle rcFont = new Rectangle(recX, 0, barcodeImageTemp.Width - recX, BARCODEHEIGHT);

                            string barStr = GetBarCodeStringByCutsom(picInfo, board);
                            if (string.IsNullOrEmpty(barStr))
                            {
                                barStr = picInfo.GridName + @"\P" + //格子号
                                         picInfo.PhotoId + @"\O" + //照片号
                                         picInfo.OrderProductId + @"\" + //产品号
                                         picInfo.Remark + "\\" +
                                         picInfo.OrderProductName + @"\" +
                                         picInfo.ShopName + @"\B" +
                                         board.BoardBaseInfo.BoardId + @"\" +
                                         picInfo.Width.ToString("0.00") + "*" +
                                         picInfo.Height.ToString("0.00") + "(" +
                                         (picInfo.Width*2.54).ToString("0.00") + "*" +
                                         (picInfo.Height*2.54).ToString("0.00") + @")\" +
                                         DateTime.Now.ToString();
                            }
                            barStr = barStr.Trim('\\').Trim().Trim('\\');
                            //barStr = barStr.Substring(barStr.IndexOf("P"));
                            //////processor.Draw3dText(gText,
                            //////                    barStr,
                            //////                    rcFont,
                            //////                    SpecialEffectsTextStyle.Normal,
                            //////                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                            //////                    0, /* horizontal  shadow position */
                            //////                    0, /* vertical shadow position */
                            //////                    FontColor,/* text color, blue */
                            //////                    Color.White,/* shadow color, black */
                            //////                    Color.White, /* border color, white */
                            //////                    textFont,
                            //////                    null);
                            //自使用字号
                            if (smallPhotosize < (float) barcodeImageTemp.Width/barcodeImageTemp.XResolution)
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;

                                gText.DrawString(barStr, textFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            else
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;
                                gText.DrawString(barStr, textSmallFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            ColorResolutionCommand gTextCommandommand =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            gTextCommandommand.Run(barcodeImageTemp);
                            gText.Dispose();
                            ColorImgBlock.Dispose(); //释放色块的资源

                            #endregion

                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombinPicAndBarcode(picInfo, ref barcodeImageTemp, ref smallPicImage, ref midImageTmp);

                            //                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            //                            Rectangle barCodeRec = new Rectangle();
                            //                            Rectangle picRec = new Rectangle();

                            //                            if (picInfo.BarCodeStatus == 0)//条码在横向上c
                            //                            {
                            //                                if (Settings.Default.BarHDirection)//默认在左边
                            //                                {

                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 90 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);
                            //                                    barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(BARCODEHEIGHT, 0, smallPicImage.Width, smallPicImage.Height);

                            //                                }
                            //                                else//右边
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 270 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);
                            //                                    barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                            }
                            //                            else if (picInfo.BarCodeStatus == 1)//0:条码放在纵向
                            //                            {
                            //                                if (Settings.Default.BarVDirection)//默认在上面
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else//下面
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }

                            //                            }
                            //                            else if (picInfo.BarCodeStatus == 2)
                            //                            {
                            //                                if (Settings.Default.BarVDirection)//默认在上面
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else//下面
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                            }
                            //                            else if (picInfo.BarCodeStatus == 3)
                            //                            {
                            //                                //查看照片是否旋转在原照片底部打印条码横向排版竖向生成条码在照片的左边就是原方向的下方
                            //                                if (picInfo.IsWhirl)
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 90 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);

                            //                                    barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, smallPicImage.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width, smallPicImage.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                            }
                            //                            else
                            //                            {
                            //                                barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                            }

                            //                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            //                            cfcBarcode.SourcePoint = Point.Empty;
                            //                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            //                            cfcBarcode.DestinationImage = midImageTmp;



                            //                            UPTLab("贴图片");
                            //                            //贴图片
                            //                            cfcBarcode.DestinationRectangle = picRec;
                            //                            cfcBarcode.Run(smallPicImage);

                            ////							codecs.Save(smallPicImage,  @"D:\123456.jpg", RasterImageFormat.Jpeg, 24);

                            //                            UPTLab("贴条码");
                            //                            //贴条码
                            //                            cfcBarcode.DestinationRectangle = barCodeRec;

                            //                            cfcBarcode.Run(barcodeImageTemp);

                            ////							codecs.Save(midImageTmp,  @"D:\1.jpg", RasterImageFormat.Jpeg, 24);

                            //                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片

                            #endregion

                        }
                        else //无条码
                        {

                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                smallPicImage.Width,
                                smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd |
                                               CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }

                        #endregion

                        UPTLab("给中间图画边框");
                        ///midImageTmp中间图

                        //midImageTmp.AddBorderToRegion(0, 0, new RasterColor(Color.Black), new RasterColor(Color.Black), new RasterColor(Color.Black), RasterRegionCombineMode.Set);

                        #region //给中间图画边框

                        if (IsPrintPhotoLine)
                        {
                            DrowBordLine(ref midImageTmp);
                        }

                        #endregion


                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }
                        //讲图片旋转
                        //RotateCommand rcTemp = new RotateCommand();//旋转条码图片               
                        //rcTemp.Angle = 90 * 100;

                        //rcTemp.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                        //rcTemp.Run(midImageTmp);
                        //RasterCodecs.Startup();
                        //RasterCodecs codecs = new RasterCodecs();
                        UPTLab("正在旋转小图...");
                        if (midImageTmp.Width >= 9000 || midImageTmp.Height >= 9000) //大于这个尺寸就用PS进行旋转
                        {
                            try
                            {
                                if (File.Exists(Application.StartupPath + "\\temHT.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temHT.jpg");
                                }
                                if (File.Exists(Application.StartupPath + "\\temH.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temH.jpg");
                                }
                            }
                            catch
                            {
                            }
                            midImageTmp.XResolution = midImageTmp.YResolution = board.BoardBaseInfo.DPI;

                            codecs.Save(midImageTmp, Application.StartupPath + "\\temHT.jpg", RasterImageFormat.Jpeg, 24);

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            if (isNeedCut) //自动裁切模式旋转90
                            {
                                // myClass.DoRotate(Application.StartupPath + "\\temHT.jpg", Application.StartupPath + "\\temH.jpg", true, 270);
                                psApp.RotatePic(Application.StartupPath + "\\temHT.jpg",
                                    Application.StartupPath + "\\temH.jpg", 270);

                                //psApplition.RotatePic(Application.StartupPath + "\\temHT.jpg",
                                //    Application.StartupPath + "\\temH.jpg", 270);

                            }
                            else
                            {

                                //myClass.DoRotate(Application.StartupPath + "\\temHT.jpg",Application.StartupPath + "\\temH.jpg", true, 270);
                                psApp.RotatePic(Application.StartupPath + "\\temHT.jpg",
                                    Application.StartupPath + "\\temH.jpg", 270);

                                //psApplition.RotatePic(Application.StartupPath + "\\temHT.jpg",
                                // Application.StartupPath + "\\temH.jpg", 270);

                            }

                            try
                            {
                                midImageTmp = codecs.Load(Application.StartupPath + "\\temH.jpg");
                            }
                            catch (Exception s)
                            {
                                //LoggingService.LogError(s);
                                throw (s)
                                    ;
                            }
                        }
                        else
                        {
                            RotateCommand rcTemp = new RotateCommand(); //旋转条码图片   
                            //if (isNeedCut)//自动裁切模式旋转270
                            //{
                            rcTemp.Angle = 270*100;

                            //}
                            //else
                            //{
                            //    rcTemp.Angle = 90 * 100;

                            //}


                            rcTemp.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                            rcTemp.Run(midImageTmp);
                            //								codecs.Save(midImageTmp,  @"D:\11.jpg", RasterImageFormat.Jpeg, 24);
                        }

                        UPTLab("将中间图贴在大图上");
                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                            pointY, //在大图上的坐标
                            pointX,
                            midImageTmp.Width, //长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (isNeedCut) //自动裁切模式
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointY;
                            photoP.Y = pointX;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;
                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X; ///居中偏移量
                            }
                        }

                        //将中间图贴在大图上
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();

                        UPTPgro(board.ListPhotos.Count, i++); //进度条
                        //this.Invoke(dlUpProgress, new int[] { board.ListPhotos.Count, ++i });
                        UPTLab("添加小图成功:" + picInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {

                        errText = picInfo.PicPath;
                        throw ex;
                    }

                }
                UPTLab("所有小图生成成功");

                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;
                //判断目录是否存在
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }
                int qipanHeight = Convert.ToInt32(0.5/2.54*board.BoardBaseInfo.DPI);

                if (isNeedCut) //自动裁切模式要替换最终destImage
                {
                    UPTLab("创建自动裁切信息");
                    ///创建大板的条码信息
                    //RasterImage destTempImage = destImage;//先将名称替换掉
                    RasterImage boardPointInfoImage = new RasterImage(
                        RasterMemoryFlags.Conventional,
                        destImage.Width,
                        qipanHeight,
                        24,
                        RasterByteOrder.Bgr,
                        RasterViewPerspective.BottomLeft,
                        null,
                        IntPtr.Zero,
                        0); //条码信息色块中间白板图

                    RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                        destImage.Width,
                        destImage.Height + qipanHeight,
                        24,
                        RasterByteOrder.Bgr,
                        RasterViewPerspective.BottomLeft,
                        null,
                        IntPtr.Zero,
                        0); //);

                    #region//OLd生成色块的信息

                    ///填充颜色
                    //FillCommand fcommandW = new FillCommand();
                    //fcommandW.Color = new RasterColor(255, 255, 255);
                    //fcommandW.Run(destTempImage);
                    //fcommandW.Run(boardPointInfoImage);
                    //destTempImage.XResolution = destImage.XResolution;

                    //destTempImage.YResolution = destImage.YResolution;
                    ////条码文字信息
                    ////Graphics g = barcodeImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                    ////SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    //int recCurrX = XExcursion, recCurrY = 0;





                    ////打定位色块第一组
                    //#region///三组定位色块
                    //RasterImage ColorImgBlockWhite = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);
                    //RasterImage ColorImgBlockBlack = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);



                    //UPTLab("粘贴色块");
                    ////粘贴色块
                    ////第一组色块中心距离原点30+偏移
                    //int currRecy = 0;
                    //for (int icolor = 0; icolor <= 10; icolor++)
                    //{
                    //    if (icolor % 2 == 0)
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy,
                    //         10,
                    //         20,
                    //         20);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockBlack);
                    //    }
                    //    else
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy,
                    //         30,
                    //         20,
                    //         20);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockWhite);
                    //    }
                    //    currRecy += 20;
                    //}

                    //int currRecy2 = destImage.Width-580;//最后一个棋盘交叉距离版右边部20cm
                    //for (int icolor = 0; icolor <=10; icolor++)
                    //{
                    //    if (icolor % 2 == 0)
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy2,
                    //         10,
                    //         20,
                    //         20);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockBlack);
                    //    }
                    //    else
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy2,
                    //         30,
                    //         20,
                    //         20);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockWhite);
                    //    }
                    //    currRecy2 += 20;
                    //}




                    //#endregion
                    //#region///文字 条码信息
                    ////条码文字
                    //SizeF sizeF = gFont.MeasureString("*" + board.BoardBaseInfo.BoardId.ToString() + "*", textBarFont);

                    ////打条码
                    //Rectangle rcBarcode = new Rectangle(2000, 5, 525, 50);//在200打75宽 50高的条码

                    //Graphics gb = boardPointInfoImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字

                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    //processor.Draw3dText(gb,
                    //                   "*" + board.BoardBaseInfo.BoardId + "*",
                    //                     rcBarcode,
                    //                     SpecialEffectsTextStyle.Normal,
                    //                     SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                    //                     0, /* horizontal  shadow position */
                    //                     0, /* vertical shadow position */
                    //                     Color.Black, /* text color, blue */
                    //                     Color.White,/* shadow color, black */
                    //                     Color.White, /* border color, white */
                    //                     textBarFont,
                    //                     null);

                    ////粘贴色块

                    ////打印文字及其区域

                    //Rectangle rcFont = new Rectangle(3100, 0, 500, 50);

                    //string barStr = board.BoardBaseInfo.BoardId.ToString();


                    //processor.Draw3dText(gb,
                    //                    barStr,
                    //                    rcFont,
                    //                    SpecialEffectsTextStyle.Normal,
                    //                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                    //                    0, /* horizontal  shadow position */
                    //                    0, /* vertical shadow position */
                    //                    Color.Black,/* text color, blue */
                    //                    Color.White,/* shadow color, black */
                    //                    Color.White, /* border color, white */
                    //                    textFont,
                    //                    null);

                    //gb.Dispose();
                    //#endregion
                    ////ClassVectorPointClass cvpc = new ClassVectorPointClass();
                    ////var pic=cvpc.GetMarkImage(destImage.Width, qipanHeight, board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    ////PictureBox pb = new PictureBox();
                    ////pb.Image = pic;
                    ////RasterImage small = new RasterImage(pic);

                    #endregion

                    //ClassVectorPointClass cvpc = new ClassVectorPointClass();
                    ////var pic = cvpc.GetMarkImage(Convert.ToInt32(boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    //TransferImage ti = new TransferImage("aa");
                    //Image image = ti.TransferPictureToImage(pic);
                    //RasterImage smallTop = new RasterImage(image);
                    if (File.Exists(Application.StartupPath + "\\temBar.bmp"))
                    {
                        File.Delete(Application.StartupPath + "\\temBar.bmp");
                    }
                    //int PixWidth=

                    //var p1 = mai.CreateMarkPicture(7620, 254, "123", "abc");
                    //var pic=mai.CreateMarkPicture(Convert.ToInt32(boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    //Image img= Microsoft.VisualBasic.Compatibility.VB6.Support.IPictureToImage(pic);
                    //RasterImage smallTop = new RasterImage(img);
                    //string aaa = cvpc.CreateMarkImageToFile(Convert.ToInt32(boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.jpg", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    var s =
                        mai.CreateMarkPictureToFile(
                            Convert.ToInt32((double) boardPixWidth/board.BoardBaseInfo.DPI*2.54*100),
                            board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp",
                            board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    //GetPictureFromIPicture(pic);
                    //AxHost ax=new TransferImage() as AxHost;
                    RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                    CombineFastCommand cfctop = new CombineFastCommand();
                    //cfctop.DestinationRectangle = new Rectangle(180, 0, boardPointInfoImage.Width, boardPointInfoImage.Height);
                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                    cfctop.SourcePoint = Point.Empty;
                    cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(smallTop);
                    cfctop.DestinationRectangle = new Rectangle(0, smallTop.Height, destImage.Width, destImage.Height);
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(destImage);
                    destImage = destTempImage; //重新赋值

                    //写入文件
                    StringBuilder sbWriter = new StringBuilder();
                    sbWriter.AppendLine(
                        (((double) board.BoardBaseInfo.PixHeight/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                        (((double) board.BoardBaseInfo.PixWidth/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                        board.BoardBaseInfo.PrintName);
                    foreach (PhotoPoint pp in listPhotoInfoForCut)
                    {
                        string mmX = (((double) pp.X/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                        string mmy = (((double) pp.Y/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                        string mmWidth = (((double) pp.Width/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                        string mmheight = (((double) pp.Height/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                        string strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                        sbWriter.AppendLine(strWriter);

                    }
                    //计算裁切尺寸
                    //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                    //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                    //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                    //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                    ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                    string FileName = destFileName.Substring(0, destFileName.LastIndexOf("@")) + ".txt";
                    if (File.Exists(FileName))
                    {
                        File.Delete(FileName);
                    }
                    CommFile.WrtieTextEn(sbWriter, FileName);
                    //_mainBLL.SetBoardAutoCutInfo(board.BoardBaseInfo.BoardId, sbWriter.ToString());

                }

                //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                //{
                //    UPTLab("正在竖向旋转90度...");


                //    RotateCommand rc = new RotateCommand();
                //    rc.Angle = 90 * 100;
                //    rc.FillColor = new RasterColor(255, 255, 255);
                //    rc.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                //    rc.Run(destImage);                
                //}
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;


                if (board.BoardBaseInfo.Sharpen > 0) //如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    Leadtools.ImageProcessing.Effects.SharpenCommand command =
                        new Leadtools.ImageProcessing.Effects.SharpenCommand();
                    command.Sharpness = board.BoardBaseInfo.Sharpen;
                    command.Run(destImage);
                }


                UPTLab("正在保存大图...");

                if (Settings.Default.AddIccByPs) //需要用PS加载ICC
                {
                    if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                    {
                        codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                    }
                    else
                    {
                        codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                    }

                }
                else //用LEADTOOLS加载ICC
                {
                    //处理旋转的问题
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    UPTLab("正在竖向旋转90度...");
                    //    if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                    //    {
                    //        try
                    //        {
                    //            File.Delete(Application.StartupPath + "\\tem.jpg");
                    //        }
                    //        catch { }

                    //        codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                    //        PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                    //        myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);
                    //        destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                    //        File.Delete(Application.StartupPath + "\\temBig.jpg");
                    //    }
                    //    else
                    //    {
                    //        RotateCommand rc = new RotateCommand();
                    //        rc.Angle = 90 * 100;
                    //        rc.FillColor = new RasterColor(255, 255, 255);
                    //        rc.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                    //        rc.Run(destImage);
                    //    }

                    //}

                    switch (PicFormat)
                    {
                        case 0:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }

                    #region//指定转换配置文件(不通过ps加载ICC时用)

                    string colorSpace = Properties.Settings.Default.ColorSpace;
                    bool setColorSpace = Properties.Settings.Default.SetColorSpace;
                    string fname = Application.StartupPath + "\\SetSpaceTem.jpg";

                    int intRatate = 0;
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    intRatate = 90;
                    //}
                    string strResult = string.Empty, strPicFormat;
                    if (setColorSpace)
                    {
                        try
                        {
                            File.Delete(Application.StartupPath + "\\SetSpaceTem.jpg");
                        }
                        catch
                        {
                        }
                        codecs.Save(destImage, Application.StartupPath + "\\SetSpaceTem.jpg", RasterImageFormat.Jpeg, 24);
                        //PSICC.ClassIccClass myclass = new PSICC.ClassIccClass();

                        //switch (PicFormat)
                        //{
                        //    case 0: strPicFormat = "JPEG"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref  intRatate);

                        //        break;
                        //    case 1: strPicFormat = "TIFF"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref intRatate);
                        //        break;
                        //}

                        psApp.AddICC(colorSpace, fname, destFileName);

                        if (strResult == destFileName)
                        {
                            UPTLab("成功转换配置文件:" + colorSpace);
                        }
                        else
                        {
                            //加载ICC失败
                            UPTLab("转换配置文件失败!" + strResult);
                            throw new Exception("转换配置文件失败!" + strResult);
                        }
                    }

                    #endregion
                }



                #region //写入ICC文件

                UPTLab("正在加载ICC文件..." + board.BoardBaseInfo.IccPath);
                if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                {
                    if (Properties.Settings.Default.AddIccByPs) //需要用PS加载ICC
                    {
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName =
                                board.BoardBaseInfo.IccPath.Substring(board.BoardBaseInfo.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName); //如果以前生成过图片，则删除已生成的
                            }
                            catch
                            {
                            }

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            string strResult = string.Empty, strPicFormat;
                            string strInputIcc = Settings.Default.ColorSpace;
                            //string strInputIcc = "ColorMatch RGB";
                            //string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90竖版生成后不需要旋转
                            //    intRatate = -90;

                            //switch (PicFormat)
                            //{
                            //    case 0: strPicFormat = "JPEG"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref  intRatate);

                            //        break;
                            //    case 1: strPicFormat = "TIFF"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                            //        break;
                            //}

                            psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                //加载ICC失败
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件失败!" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath); //删除保存到C盘的零时的图片文件
                            }
                            catch
                            {
                            }
                        }
                    }
                    else //用LEADTOOLS加载ICC
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) &&
                                File.Exists(board.BoardBaseInfo.IccPath))
                            {
                                IccProfileExtended iccProfile = new IccProfileExtended(board.BoardBaseInfo.IccPath);
                                iccProfile.WriteToImage(destFileName, destImage.PageCount);
                            }

                        }
                        catch (Exception ef)
                        {
                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }
                    }
                }

                #endregion

                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0); //进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                _mainBLL.MakeBigPicSusscess(board.BoardBaseInfo.BoardId, destFileName); //生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");
            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //errText = "生成大图错误"+ex1.Message;
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int) EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }

        /// <summary>
        /// 横向排竖向生成裁切标记在前面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2VCutBeforePic(BoardInfo_ProductBigPic board)
        {
            //var p1 = mai.CreateMarkPictureToFile(7620, 254,@"c:\1234.bmp", "123", "abc");

            int i = 0; //当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath; //最终大图的保存路径
            int boardPixWidth = board.BoardBaseInfo.PixHeight; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.PixWidth; //大图的高,相素
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();
            string errText = "";
            int XExcursion = 0;
            if (PicFormat < 0)
            {
                PicFormat = 0;
            }
            XExcursion = boardPixWidth;


            if (PicFormat == 1)
            {
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            //string msg = "正在生成：" + destFileName;
            //this.Invoke(dlUplbl, new string[] { "正在生成：" + destFileName });
            UPTLab("正在生成：" + destFileName);
            //this.Invoke(dlUpProgress, new int[] { 0, 0 });
            UPTPgro(0, 0);

            //if (board.BoardBaseInfo.Printer.IsAutoCut && Settings.Default.MinAutoCut < board.ListPhotos.Count)
            //    isNeedCut = true;
            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
                ///条码文件

                string aaa =
                    mai.CreateMarkPictureToFile(
                        Convert.ToInt32((double) boardPixWidth/board.BoardBaseInfo.DPI*2.54*100),
                        board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp",
                        board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");


                int offsetW = smallTop.Height;


                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Tiled,
                    boardPixWidth,
                    BoardPixHeight + offsetW, //加上裁切标记的宽宽度
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                FillCommand fcommand = new FillCommand();

                fcommand.Color = new RasterColor(Settings.Default.BackColor.R, Settings.Default.BackColor.G,
                    Settings.Default.BackColor.B);
                fcommand.Run(destImage);

                //将裁切信息粘贴到大板上
                CombineFastCommand cfctop = new CombineFastCommand();
                cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(smallTop);


                UPTLab("生大大图框架成功");
                foreach (var picInfo in board.ListPhotos)
                {
                    if (picInfo.labelWidth != 0)
                    {
                        BARCODEHEIGHT = picInfo.labelWidth;
                    }
                    int temp = 0; //temp=picInfo.PixHeight;
                    //picInfo.PixHeight = picInfo.PixWidth;
                    //picInfo.PixWidth = temp;


                    //picInfo.IsWhirl = !picInfo.IsWhirl;
                    UPTLab("正在添加小图:" + picInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上

                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.PicPath))
                        {
                            throw new Exception("文件不存在：" + picInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board); //小图片
                        DrowBordLine(ref smallPicImage, Color.Green);
                        RasterImage midImageTmp = CreateMidImg(picInfo, board); //带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");

                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        //if (picInfo.BarCodeStatus != 2 || (picInfo.BarCodeStatus==2&&Settings.Default.BoolPrintInphoto))//有条码
                        //{
                        if (picInfo.BarCodeStatus != 2) //有条码c
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board); //条码图片的临时图片

                            RasterImage ColorImgBlock = GetProductColorBlock(picInfo.OrderProductId); //色块,根据产品得到不同的色块


                            #region//条码信息有限处理

                            Graphics gBarcode = barcodeImageTemp.CreateGdiPlusGraphics().Graphics; //用来打印条码和文字
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            //int recX = ColorImgBlock.Width + 10, recY = 0;
                            int recX = ColorImgBlock.Width, recY = 0; //当前操作在条码图片上的位置

                            SizeF sizeF = gFont.MeasureString("*" + picInfo.PhotoId.ToString() + "*", textBarFont);
                            //sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution;
                            BARCODEWIDTH = Convert.ToInt32(sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution) + 10;
                                //条码的宽度

                            bool isPrintBarCode = false; //是否要打印条码
                            if (Settings.Default.SmallSizeToPrintBarCode <= 0)
                            {
                                isPrintBarCode = BARCODEWIDTH + 100 <= barcodeImageTemp.Width;
                            }
                            else
                            {
                                isPrintBarCode = barcodeImageTemp.Width >
                                                 Settings.Default.SmallSizeToPrintBarCode*board.BoardBaseInfo.DPI;
                            }

                            //if (BARCODEWIDTH + 100 <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (isPrintBarCode) //如果照片的宽度大于5寸才打印条码,目的是为了显示更多的有用的信息
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIGHT);


                                gBarcode.DrawString("*" + picInfo.PhotoId.ToString() + "*", textBarFont, Brushes.Black,
                                    recX, recY);
                                recX += BARCODEWIDTH;


                            }
                            gBarcode.Dispose();
                            ColorResolutionCommand command =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            command.Run(barcodeImageTemp);

                            #endregion

                            UPTLab("粘贴色块");

                            #region//粘贴色块

                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                barcodeImageTemp.Width,
                                barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd |
                                                CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);

                            #endregion

                            UPTLab("生成条码及文字");

                            #region 文字信息



                            //写其文字信息
                            Graphics gText = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;
                            //recX += 10;
                            Rectangle rcFont = new Rectangle(recX, 0, barcodeImageTemp.Width - recX, BARCODEHEIGHT);

                            string barStr = GetBarCodeStringByCutsom(picInfo, board);
                            if (string.IsNullOrEmpty(barStr))
                            {
                                barStr = picInfo.GridName + @"\P" + //格子号
                                         picInfo.PhotoId + @"\O" + //照片号
                                         picInfo.OrderProductId + @"\" + //产品号
                                         picInfo.Remark + "\\" +
                                         picInfo.OrderProductName + @"\" +
                                         picInfo.ShopName + @"\B" +
                                         board.BoardBaseInfo.BoardId + @"\" +
                                         picInfo.Width.ToString("0.00") + "*" +
                                         picInfo.Height.ToString("0.00") + "(" +
                                         (picInfo.Width*2.54).ToString("0.00") + "*" +
                                         (picInfo.Height*2.54).ToString("0.00") + @")\" +
                                         DateTime.Now.ToString();
                            }
                            barStr = barStr.Trim('\\').Trim().Trim('\\');
                            //barStr = barStr.Substring(barStr.IndexOf("P"));
                            ////processor.Draw3dText(gText,
                            ////                    barStr,
                            ////                    rcFont,
                            ////                    SpecialEffectsTextStyle.Normal,
                            ////                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                            ////                    0, /* horizontal  shadow position */
                            ////                    0, /* vertical shadow position */
                            ////                    FontColor,/* text color, blue */
                            ////                    Color.White,/* shadow color, black */
                            ////                    Color.White, /* border color, white */
                            ////                    textFont,
                            ////                    null);
                            //自使用字号
                            if (smallPhotosize < (float) barcodeImageTemp.Width/barcodeImageTemp.XResolution)
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;

                                gText.DrawString(barStr, textFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            else
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;
                                gText.DrawString(barStr, textSmallFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            ColorResolutionCommand gTextCommandommand =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            gTextCommandommand.Run(barcodeImageTemp);
                            gText.Dispose();
                            ColorImgBlock.Dispose(); //释放色块的资源

                            #endregion


                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombinPicAndBarcode(picInfo, ref barcodeImageTemp, ref smallPicImage, ref midImageTmp);
                            //                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            //                            Rectangle barCodeRec, picRec;

                            //                            if (picInfo.BarCodeStatus == 0)//条码在横向上c
                            //                            {


                            //                                if (Settings.Default.BarHDirection)//默认在左边
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 90 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);
                            //                                    barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(BARCODEHEIGHT, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else//右边
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 270 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);
                            //                                    barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIGHT, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                            }
                            //                            else if (picInfo.BarCodeStatus == 1)//0:条码放在纵向
                            //                            {
                            //                                if (Settings.Default.BarVDirection)//默认在上面
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width,smallPicImage.Height);
                            //                                }
                            //                                else//下面
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }

                            //                            }
                            //                            else if (picInfo.BarCodeStatus == 3)
                            //                            {
                            //                               //查看照片是否旋转在原照片底部打印条码横向排版竖向生成条码在照片的左边就是原方向的下方
                            //                                if (picInfo.IsWhirl)
                            //                                {
                            //                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //                                    rcBarcode.Angle = 90 * 100;
                            //                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //                                    rcBarcode.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                            //                                    rcBarcode.Run(barcodeImageTemp);

                            //                                    barCodeRec = new Rectangle(0, 0, BARCODEHEIGHT, smallPicImage.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }
                            //                                else
                            //                                {
                            //                                    barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width, smallPicImage.Height);
                            //                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                                }

                            //                            }
                            //                            else
                            //                            {
                            //                                barCodeRec = new Rectangle(0, smallPicImage.Height - barcodeImageTemp.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                            //                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //                            }

                            //                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            //                            cfcBarcode.SourcePoint = Point.Empty;
                            //                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            //                            cfcBarcode.DestinationImage = midImageTmp;



                            //                            UPTLab("贴图片");
                            //                            //贴图片
                            //                            cfcBarcode.DestinationRectangle = picRec;
                            //                            cfcBarcode.Run(smallPicImage);

                            //                            UPTLab("贴条码");
                            //                            //贴条码
                            //                            cfcBarcode.DestinationRectangle = barCodeRec;

                            //                            cfcBarcode.Run(barcodeImageTemp);

                            ////	                        codecs.Save(midImageTmp, @"d:\123.jpg", RasterImageFormat.Jpeg, 24);

                            //                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片


                            #endregion



                        }
                        else if (picInfo.BarCodeStatus == 2) //无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                smallPicImage.Width,
                                smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd |
                                               CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }
                        else
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                smallPicImage.Width,
                                smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd |
                                               CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }

                        #endregion

                        UPTLab("给中间图画边框");
                        ///midImageTmp中间图

                        //midImageTmp.AddBorderToRegion(0, 0, new RasterColor(Color.Black), new RasterColor(Color.Black), new RasterColor(Color.Black), RasterRegionCombineMode.Set);


                        #region //给中间图画边框

                        if (IsPrintPhotoLine)
                        {
                            DrowBordLine(ref midImageTmp);
                        }

                        #endregion


                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }
                        //讲图片旋转
                        //RotateCommand rcTemp = new RotateCommand();//旋转条码图片               
                        //rcTemp.Angle = 90 * 100;

                        //rcTemp.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                        //rcTemp.Run(midImageTmp);
                        //RasterCodecs.Startup();
                        //RasterCodecs codecs = new RasterCodecs();
                        UPTLab("正在旋转小图...");
                        if (midImageTmp.Width >= 9000 || midImageTmp.Height >= 9000) //大于这个尺寸就用PS进行旋转
                        {
                            try
                            {
                                if (File.Exists(Application.StartupPath + "\\temHT.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temHT.jpg");
                                }
                                if (File.Exists(Application.StartupPath + "\\temH.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temH.jpg");
                                }
                            }
                            catch
                            {
                            }
                            midImageTmp.XResolution = midImageTmp.YResolution = board.BoardBaseInfo.DPI;

                            codecs.Save(midImageTmp, Application.StartupPath + "\\temHT.jpg", RasterImageFormat.Jpeg, 24);

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();

                            //myClass.DoRotate(Application.StartupPath + "\\temHT.jpg", Application.StartupPath + "\\temH.jpg", true, 270);

                            psApp.RotatePic(Application.StartupPath + "\\temHT.jpg",
                                Application.StartupPath + "\\temH.jpg", 270);

                            midImageTmp = codecs.Load(Application.StartupPath + "\\temH.jpg");

                        }
                        else
                        {
                            RotateCommand rcTemp = new RotateCommand(); //旋转条码图片   

                            rcTemp.Angle = 270*100;




                            rcTemp.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                            rcTemp.Run(midImageTmp);
                        }

                        UPTLab("将中间图贴在大图上");
                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                            pointY, //在大图上的坐标
                            pointX + offsetW, //往下移动裁切标的距离
                            midImageTmp.Width, //长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);

                        //计算裁切尺寸

                        PhotoPoint photoP = new PhotoPoint();

                        photoP.X = pointY;
                        photoP.Y = pointX;
                        photoP.Width = midImageTmp.Width;
                        photoP.Height = midImageTmp.Height;
                        listPhotoInfoForCut.Add(photoP);
                        if (XExcursion > photoP.X)
                        {
                            XExcursion = photoP.X; ///居中偏移量
                        }


                        //将中间图贴在大图上
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();

                        UPTPgro(board.ListPhotos.Count, i++); //进度条
                        //this.Invoke(dlUpProgress, new int[] { board.ListPhotos.Count, ++i });
                        UPTLab("添加小图成功:" + picInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {

                        errText = picInfo.PicPath;
                        throw ex;
                    }

                }
                UPTLab("所有小图生成成功");

                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;
                //判断目录是否存在
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                //写入文件
                StringBuilder sbWriter = new StringBuilder();
                sbWriter.AppendLine(
                    (((double) board.BoardBaseInfo.PixHeight/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    (((double) board.BoardBaseInfo.PixWidth/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    board.BoardBaseInfo.PrintName);
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {
                    string mmX = (((double) pp.X/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmy = (((double) pp.Y/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmWidth = (((double) pp.Width/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmheight = (((double) pp.Height/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    sbWriter.AppendLine(strWriter);

                }

                string FileName = destFileName.Substring(0, destFileName.LastIndexOf("@")) + ".txt";
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                CommFile.WrtieTextEn(sbWriter, FileName);
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;


                if (board.BoardBaseInfo.Sharpen > 0) //如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    Leadtools.ImageProcessing.Effects.SharpenCommand command =
                        new Leadtools.ImageProcessing.Effects.SharpenCommand();
                    command.Sharpness = board.BoardBaseInfo.Sharpen;
                    command.Run(destImage);
                }


                UPTLab("正在保存大图...");

                if (Settings.Default.AddIccByPs) //需要用PS加载ICC
                {
                    if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                    {
                        codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                    }
                    else
                    {
                        codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                    }

                }
                else //用LEADTOOLS加载ICC
                {


                    switch (PicFormat)
                    {
                        case 0:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }

                    #region//指定转换配置文件(不通过ps加载ICC时用)

                    string colorSpace = Properties.Settings.Default.ColorSpace;
                    bool setColorSpace = Properties.Settings.Default.SetColorSpace;
                    string fname = Application.StartupPath + "\\SetSpaceTem.jpg";

                    int intRatate = 0;
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    intRatate = 90;
                    //}
                    string strResult = string.Empty, strPicFormat;
                    if (setColorSpace)
                    {
                        try
                        {
                            File.Delete(Application.StartupPath + "\\SetSpaceTem.jpg");
                        }
                        catch
                        {
                        }
                        codecs.Save(destImage, Application.StartupPath + "\\SetSpaceTem.jpg", RasterImageFormat.Jpeg, 24);
                        //PSICC.ClassIccClass myclass = new PSICC.ClassIccClass();

                        //switch (PicFormat)
                        //{
                        //    case 0: strPicFormat = "JPEG"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref  intRatate);

                        //        break;
                        //    case 1: strPicFormat = "TIFF"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref intRatate);
                        //        break;
                        //}

                        psApp.AddICC(colorSpace, fname, destFileName);

                        if (strResult == destFileName)
                        {
                            UPTLab("成功转换配置文件:" + colorSpace);
                        }
                        else
                        {
                            //加载ICC失败
                            UPTLab("转换配置文件失败!" + strResult);
                            throw new Exception("转换配置文件失败!" + strResult);
                        }
                    }

                    #endregion
                }



                #region //写入ICC文件

                UPTLab("正在加载ICC文件..." + board.BoardBaseInfo.IccPath);
                if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                {
                    if (Properties.Settings.Default.AddIccByPs) //需要用PS加载ICC
                    {
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName =
                                board.BoardBaseInfo.IccPath.Substring(board.BoardBaseInfo.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName); //如果以前生成过图片，则删除已生成的
                            }
                            catch
                            {
                            }

                            // PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            string strResult = string.Empty, strPicFormat;
                            string strInputIcc = Settings.Default.ColorSpace;
                            //string strInputIcc = "ColorMatch RGB";
                            //string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90竖版生成后不需要旋转
                            //    intRatate = -90;

                            //switch (PicFormat)
                            //{
                            //    case 0: strPicFormat = "JPEG"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref  intRatate);

                            //        break;
                            //    case 1: strPicFormat = "TIFF"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                            //        break;
                            //}

                            psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                //加载ICC失败
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件失败!" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath); //删除保存到C盘的零时的图片文件
                            }
                            catch
                            {
                            }
                        }
                    }
                    else //用LEADTOOLS加载ICC
                    {
                        if (File.Exists(board.BoardBaseInfo.IccPath))
                        {
                            try
                            {
                                IccProfileExtended iccProfile = new IccProfileExtended(board.BoardBaseInfo.IccPath);
                                iccProfile.WriteToImage(destFileName, destImage.PageCount);

                            }
                            catch (Exception ef)
                            {
                                UPTLab("加载ICC文件错误:" + ef.Message);
                                throw new Exception("加载ICC文件错误" + ef.Message);
                            }
                        }
                    }
                }

                #endregion

                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0); //进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                _mainBLL.MakeBigPicSusscess(board.BoardBaseInfo.BoardId, destFileName); //生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");
            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //errText = "生成大图错误"+ex1.Message;
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int) EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }

        /// <summary>
        /// 横向排竖向生成裁切标记在后面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2VCutAfterPic(BoardInfo_ProductBigPic board)
        {
            //var p1 = mai.CreateMarkPictureToFile(7620, 254,@"c:\1234.bmp", "123", "abc");

            int i = 0; //当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath; //最终大图的保存路径
            int boardPixWidth = board.BoardBaseInfo.PixHeight; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.PixWidth; //大图的高,相素
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();
            string errText = "";
            int XExcursion = 0;
            if (PicFormat < 0)
            {
                PicFormat = 0;
            }
            XExcursion = boardPixWidth;



            if (PicFormat == 1)
            {
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            //string msg = "正在生成：" + destFileName;
            //this.Invoke(dlUplbl, new string[] { "正在生成：" + destFileName });
            UPTLab("正在生成：" + destFileName);
            //this.Invoke(dlUpProgress, new int[] { 0, 0 });
            UPTPgro(0, 0);

            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
                ///生成裁切标
                string aaa =
                    mai.CreateMarkPictureToFile(
                        Convert.ToInt32((double) boardPixWidth/board.BoardBaseInfo.DPI*2.54*100),
                        board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp",
                        board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                //旋转裁切标记到符合的角度
                RotateCommand rcSmall = new RotateCommand(); //旋转条码图片               
                rcSmall.Angle = 180*100;
                rcSmall.FillColor = new RasterColor(255, 255, 255);
                rcSmall.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                rcSmall.Run(smallTop);

                int offsetW = smallTop.Height;
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Tiled,
                    boardPixWidth,
                    BoardPixHeight + offsetW, ///加上裁切标记宽度
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                FillCommand fcommand = new FillCommand();

                fcommand.Color = new RasterColor(Settings.Default.BackColor.R, Settings.Default.BackColor.G,
                    Settings.Default.BackColor.B);
                
                fcommand.Run(destImage);


                ///将裁切标记合成到大板上
                CombineFastCommand cfctop = new CombineFastCommand();
                cfctop.DestinationRectangle = new Rectangle(0, BoardPixHeight, smallTop.Width, smallTop.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(smallTop);

                UPTLab("生大大图框架成功");
                foreach (PhotoInfo_ProductBigPic picInfo in board.ListPhotos)
                {
                    if (picInfo.labelWidth != 0)
                    {
                        BARCODEHEIGHT = picInfo.labelWidth;
                    }
                    int temp = 0;
                    //temp=picInfo.PixHeight;
                    //picInfo.PixHeight = picInfo.PixWidth;
                    //picInfo.PixWidth = temp;


                    //picInfo.IsWhirl = !picInfo.IsWhirl;
                    UPTLab("正在添加小图:" + picInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上

                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.PicPath))
                        {
                            throw new Exception("文件不存在：" + picInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board); //小图片
                        DrowBordLine(ref smallPicImage, Color.Green);
                        RasterImage midImageTmp = CreateMidImg(picInfo, board); //带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");

                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.BarCodeStatus != 2) //有条码
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board); //条码图片的临时图片

                            RasterImage ColorImgBlock = GetProductColorBlock(picInfo.OrderProductId); //色块,根据产品得到不同的色块


                            #region//条码信息有限处理

                            Graphics gBarcode = barcodeImageTemp.CreateGdiPlusGraphics().Graphics; //用来打印条码和文字
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            //int recX = ColorImgBlock.Width + 10, recY = 0;
                            int recX = ColorImgBlock.Width, recY = 0; //当前操作在条码图片上的位置

                            SizeF sizeF = gFont.MeasureString("*" + picInfo.PhotoId.ToString() + "*", textBarFont);
                            //sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution;
                            BARCODEWIDTH = Convert.ToInt32(sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution) + 10;
                                //条码的宽度

                            bool isPrintBarCode = false; //是否要打印条码
                            if (Settings.Default.SmallSizeToPrintBarCode <= 0)
                            {
                                isPrintBarCode = BARCODEWIDTH + 100 <= barcodeImageTemp.Width;
                            }
                            else
                            {
                                isPrintBarCode = barcodeImageTemp.Width >
                                                 Settings.Default.SmallSizeToPrintBarCode*board.BoardBaseInfo.DPI;
                            }

                            //if (BARCODEWIDTH + 100 <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (isPrintBarCode) //如果照片的宽度大于5寸才打印条码,目的是为了显示更多的有用的信息
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIGHT);
                                gBarcode.DrawString("*" + picInfo.PhotoId.ToString() + "*", textBarFont, Brushes.Black,
                                    recX, recY);
                                recX += BARCODEWIDTH;


                            }
                            gBarcode.Dispose();
                            ColorResolutionCommand command =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            command.Run(barcodeImageTemp);

                            #endregion

                            UPTLab("粘贴色块");

                            #region//粘贴色块

                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                barcodeImageTemp.Width,
                                barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd |
                                                CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);

                            #endregion

                            UPTLab("生成条码及文字");

                            #region 文字信息



                            //写其文字信息
                            Graphics gText = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;
                            //recX += 10;
                            Rectangle rcFont = new Rectangle(recX, 0, barcodeImageTemp.Width - recX, BARCODEHEIGHT);

                            string barStr = GetBarCodeStringByCutsom(picInfo, board);
                            if (string.IsNullOrEmpty(barStr))
                            {
                                barStr = picInfo.GridName + @"\P" + //格子号
                                         picInfo.PhotoId + @"\O" + //照片号
                                         picInfo.OrderProductId + @"\" + //产品号
                                         picInfo.Remark + "\\" +
                                         picInfo.OrderProductName + @"\" +
                                         picInfo.ShopName + @"\B" +
                                         board.BoardBaseInfo.BoardId + @"\" +
                                         picInfo.Width.ToString("0.00") + "*" +
                                         picInfo.Height.ToString("0.00") + "(" +
                                         (picInfo.Width*2.54).ToString("0.00") + "*" +
                                         (picInfo.Height*2.54).ToString("0.00") + @")\" +
                                         DateTime.Now.ToString();
                            }
                            barStr = barStr.Trim('\\').Trim().Trim('\\');
                            //barStr = barStr.Substring(barStr.IndexOf("P"));
                            ////processor.Draw3dText(gText,
                            ////                    barStr,
                            ////                    rcFont,
                            ////                    SpecialEffectsTextStyle.Normal,
                            ////                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                            ////                    0, /* horizontal  shadow position */
                            ////                    0, /* vertical shadow position */
                            ////                    FontColor,/* text color, blue */
                            ////                    Color.White,/* shadow color, black */
                            ////                    Color.White, /* border color, white */
                            ////                    textFont,
                            ////                    null);
                            //自使用字号
                            if (smallPhotosize < (float) barcodeImageTemp.Width/barcodeImageTemp.XResolution)
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;

                                gText.DrawString(barStr, textFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            else
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;
                                gText.DrawString(barStr, textSmallFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            ColorResolutionCommand gTextCommandommand =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            gTextCommandommand.Run(barcodeImageTemp);
                            gText.Dispose();
                            ColorImgBlock.Dispose(); //释放色块的资源

                            #endregion

                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            CombinPicAndBarcode(picInfo, ref barcodeImageTemp, ref smallPicImage, ref midImageTmp);
                            barcodeImageTemp.Dispose(); //释放条码(包含条码和文字信息)图片
                        }
                        else //无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                smallPicImage.Width,
                                smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd |
                                               CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }

                        #endregion

                        UPTLab("给中间图画边框");
                        ///midImageTmp中间图

                        //midImageTmp.AddBorderToRegion(0, 0, new RasterColor(Color.Black), new RasterColor(Color.Black), new RasterColor(Color.Black), RasterRegionCombineMode.Set);


                        #region //给中间图画边框

                        if (IsPrintPhotoLine)
                        {
                            DrowBordLine(ref midImageTmp);
                        }

                        #endregion


                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }
                        UPTLab("正在旋转小图...");
                        if (midImageTmp.Width >= 9000 || midImageTmp.Height >= 9000) //大于这个尺寸就用PS进行旋转
                        {
                            try
                            {
                                if (File.Exists(Application.StartupPath + "\\temHT.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temHT.jpg");
                                }
                                if (File.Exists(Application.StartupPath + "\\temH.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temH.jpg");
                                }
                            }
                            catch
                            {
                            }
                            midImageTmp.XResolution = midImageTmp.YResolution = board.BoardBaseInfo.DPI;

                            codecs.Save(midImageTmp, Application.StartupPath + "\\temHT.jpg", RasterImageFormat.Jpeg, 24);

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();

                            //myClass.DoRotate(Application.StartupPath + "\\temHT.jpg", Application.StartupPath + "\\temH.jpg", true, 270);

                            psApp.RotatePic(Application.StartupPath + "\\temHT.jpg",
                                Application.StartupPath + "\\temH.jpg", 270);


                            midImageTmp = codecs.Load(Application.StartupPath + "\\temH.jpg");

                        }
                        else
                        {
                            RotateCommand rcTemp = new RotateCommand(); //旋转条码图片   
                            rcTemp.Angle = 270*100;
                            rcTemp.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                            rcTemp.Run(midImageTmp);
                        }

                        UPTLab("将中间图贴在大图上");
                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                            pointY, //在大图上的坐标
                            pointX,
                            midImageTmp.Width, //长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);

                        //计算裁切尺寸

                        PhotoPoint photoP = new PhotoPoint();

                        photoP.X = board.BoardBaseInfo.PixHeight - (pointY + midImageTmp.Width);
                        photoP.Y = board.BoardBaseInfo.PixWidth - (pointX + midImageTmp.Height);

                        if (photoP.Y < 0)
                        {
                            photoP.Y = 0;
                        }
                        if (photoP.X < 0)
                        {
                            photoP.X = 0;
                        }
                        photoP.Width = midImageTmp.Width;
                        photoP.Height = midImageTmp.Height;
                        listPhotoInfoForCut.Add(photoP);
                        if (XExcursion > photoP.X)
                        {
                            XExcursion = photoP.X; ///居中偏移量
                        }


                        //将中间图贴在大图上
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();

                        UPTPgro(board.ListPhotos.Count, i++); //进度条
                        //this.Invoke(dlUpProgress, new int[] { board.ListPhotos.Count, ++i });
                        UPTLab("添加小图成功:" + picInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {

                        errText = picInfo.PicPath;
                        throw ex;
                    }

                }
                UPTLab("所有小图生成成功");

                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;
                //判断目录是否存在
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }
                //写入文件
                StringBuilder sbWriter = new StringBuilder();
                sbWriter.AppendLine(
                    (((double) board.BoardBaseInfo.PixHeight/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    (((double) board.BoardBaseInfo.PixWidth/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    board.BoardBaseInfo.PrintName);
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {
                    string mmX = (((double) pp.X/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmy = (((double) pp.Y/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmWidth = (((double) pp.Width/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmheight = (((double) pp.Height/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    sbWriter.AppendLine(strWriter);

                }

                string FileName = destFileName.Substring(0, destFileName.LastIndexOf("@")) + ".txt";
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                CommFile.WrtieTextEn(sbWriter, FileName);
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;


                if (board.BoardBaseInfo.Sharpen > 0) //如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    Leadtools.ImageProcessing.Effects.SharpenCommand command =
                        new Leadtools.ImageProcessing.Effects.SharpenCommand();
                    command.Sharpness = board.BoardBaseInfo.Sharpen;
                    command.Run(destImage);
                }


                UPTLab("正在保存大图...");

                if (Settings.Default.AddIccByPs) //需要用PS加载ICC
                {
                    if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                    {
                        codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                    }
                    else
                    {
                        codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                    }

                }
                else //用LEADTOOLS加载ICC
                {


                    switch (PicFormat)
                    {
                        case 0:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }

                    #region//指定转换配置文件(不通过ps加载ICC时用)

                    string colorSpace = Properties.Settings.Default.ColorSpace;
                    bool setColorSpace = Properties.Settings.Default.SetColorSpace;
                    string fname = Application.StartupPath + "\\SetSpaceTem.jpg";

                    int intRatate = 0;

                    string strResult = string.Empty, strPicFormat;
                    if (setColorSpace)
                    {
                        try
                        {
                            File.Delete(fname);
                        }
                        catch
                        {
                        }
                        codecs.Save(destImage, fname, RasterImageFormat.Jpeg, 24);
                        // PSICC.ClassIccClass myclass = new PSICC.ClassIccClass();


                        //switch (PicFormat)
                        //{
                        //    //case 0: strPicFormat = "JPEG"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref  intRatate);

                        //    //    break;
                        //    //case 1: strPicFormat = "TIFF"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref intRatate);
                        //    //    break;
                        //}
                        psApp.AddICC(colorSpace, fname, destFileName);


                        if (strResult == destFileName)
                        {
                            UPTLab("成功转换配置文件:" + colorSpace);
                        }
                        else
                        {
                            //加载ICC失败
                            UPTLab("转换配置文件失败!" + strResult);
                            throw new Exception("转换配置文件失败!" + strResult);
                        }
                    }

                    #endregion
                }



                #region //写入ICC文件

                UPTLab("正在加载ICC文件..." + board.BoardBaseInfo.IccPath);
                if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                {
                    if (Properties.Settings.Default.AddIccByPs) //需要用PS加载ICC
                    {
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName =
                                board.BoardBaseInfo.IccPath.Substring(board.BoardBaseInfo.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName); //如果以前生成过图片，则删除已生成的
                            }
                            catch
                            {
                            }

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            string strResult = string.Empty, strPicFormat;
                            string strInputIcc = Settings.Default.ColorSpace;
                            //string strInputIcc = "ColorMatch RGB";
                            //string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90竖版生成后不需要旋转
                            //    intRatate = -90;

                            //switch (PicFormat)
                            //{
                            //    case 0: strPicFormat = "JPEG";
                            //        strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref  intRatate);

                            //        break;
                            //    case 1: strPicFormat = "TIFF"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                            //        break;
                            //}
                            psApp.AddICC(iccName, strTempPath, destFileName);
                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                //加载ICC失败
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件失败!" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath); //删除保存到C盘的零时的图片文件
                            }
                            catch
                            {
                            }
                        }
                    }
                    else //用LEADTOOLS加载ICC
                    {
                        if (File.Exists(board.BoardBaseInfo.IccPath))
                        {
                            try
                            {
                                IccProfileExtended iccProfile = new IccProfileExtended(board.BoardBaseInfo.IccPath);
                                iccProfile.WriteToImage(destFileName, destImage.PageCount);

                            }
                            catch (Exception ef)
                            {
                                UPTLab("加载ICC文件错误:" + ef.Message);
                                throw new Exception("加载ICC文件错误" + ef.Message);
                            }
                        }
                    }
                }

                #endregion

                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0); //进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                _mainBLL.MakeBigPicSusscess(board.BoardBaseInfo.BoardId, destFileName); //生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");
            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //errText = "生成大图错误"+ex1.Message;
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int) EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }

        /// <summary>
        /// 横向排横向生成裁切标记在前面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2HCutBeforePic(BoardInfo_ProductBigPic board)
        {
            //var p1 = mai.CreateMarkPictureToFile(7620, 254,@"c:\1234.bmp", "123", "abc");

            int i = 0; //当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath; //最终大图的保存路径
            int boardPixWidth = board.BoardBaseInfo.PixWidth; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.PixHeight; //大图的高,相素
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();
            string errText = "";
            int XExcursion = 0;
            if (PicFormat < 0)
            {
                PicFormat = 0;
            }
            XExcursion = boardPixWidth;



            if (PicFormat == 1)
            {
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }

            UPTLab("正在生成：" + destFileName);
            //this.Invoke(dlUpProgress, new int[] { 0, 0 });
            UPTPgro(0, 0);
            //生成裁切标记



            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();

                string aaa =
                    mai.CreateMarkPictureToFile(
                        Convert.ToInt32((double) BoardPixHeight/board.BoardBaseInfo.DPI*2.54*100),
                        board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp",
                        board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                //旋转270条码
                //旋转裁切标记
                RotateCommand rcSmall = new RotateCommand(); //旋转条码图片               
                rcSmall.Angle = 270*100;
                rcSmall.FillColor = new RasterColor(255, 255, 255);
                rcSmall.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                rcSmall.Run(smallTop);

                int offsetW = smallTop.Width;

                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Tiled,
                    boardPixWidth + offsetW,
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                FillCommand fcommand = new FillCommand();

                fcommand.Color = new RasterColor(Settings.Default.BackColor.R, Settings.Default.BackColor.G,
                    Settings.Default.BackColor.B);
                fcommand.Run(destImage);


                //添加裁切信息

                CombineFastCommand cfctop = new CombineFastCommand();
                cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(smallTop);


                UPTLab("生大大图框架成功");
                foreach (var picInfo in board.ListPhotos)
                {
                    if (picInfo.labelWidth != 0)
                    {
                        BARCODEHEIGHT = picInfo.labelWidth;
                    }
                    int temp = 0;
                    //temp=picInfo.PixHeight;
                    //picInfo.PixHeight = picInfo.PixWidth;
                    //picInfo.PixWidth = temp;


                    //picInfo.IsWhirl = !picInfo.IsWhirl;
                    UPTLab("正在添加小图:" + picInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上

                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.PicPath))
                        {
                            throw new Exception("文件不存在：" + picInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board); //小图片
                        DrowBordLine(ref smallPicImage, Color.Green);
                        RasterImage midImageTmp = CreateMidImg(picInfo, board); //带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");

                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.BarCodeStatus != 2) //有条码
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board); //条码图片的临时图片

                            RasterImage ColorImgBlock = GetProductColorBlock(picInfo.OrderProductId); //色块,根据产品得到不同的色块


                            #region//条码信息有限处理

                            Graphics gBarcode = barcodeImageTemp.CreateGdiPlusGraphics().Graphics; //用来打印条码和文字

                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            //int recX = ColorImgBlock.Width + 10, recY = 0;
                            int recX = ColorImgBlock.Width, recY = 0; //当前操作在条码图片上的位置

                            SizeF sizeF = gFont.MeasureString("*" + picInfo.PhotoId.ToString() + "*", textBarFont);
                            BARCODEWIDTH = Convert.ToInt32(sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution) + 10;
                                //条码的宽度

                            bool isPrintBarCode = false; //是否要打印条码
                            if (Settings.Default.SmallSizeToPrintBarCode <= 0)
                            {
                                isPrintBarCode = BARCODEWIDTH + 100 <= barcodeImageTemp.Width;
                            }
                            else
                            {
                                isPrintBarCode = barcodeImageTemp.Width >
                                                 Settings.Default.SmallSizeToPrintBarCode*board.BoardBaseInfo.DPI;
                            }

                            //if (BARCODEWIDTH + 100 <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (isPrintBarCode) //如果照片的宽度大于5寸才打印条码,目的是为了显示更多的有用的信息
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIGHT);

                                gBarcode.DrawString("*" + picInfo.PhotoId.ToString() + "*", textBarFont, Brushes.Black,
                                    recX, recY);
                                recX += BARCODEWIDTH;
                            }
                            gBarcode.Dispose();
                            ColorResolutionCommand command =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            command.Run(barcodeImageTemp);

                            #endregion

                            UPTLab("粘贴色块");

                            #region//粘贴色块

                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                barcodeImageTemp.Width,
                                barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd |
                                                CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);

                            #endregion

                            UPTLab("生成条码及文字");

                            #region 文字信息

                            Graphics gText = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;

                            //写其文字信息

                            //recX += 10;
                            Rectangle rcFont = new Rectangle(recX, 0, barcodeImageTemp.Width - recX, BARCODEHEIGHT);

                            string barStr = GetBarCodeStringByCutsom(picInfo, board);
                            if (string.IsNullOrEmpty(barStr))
                            {
                                barStr = picInfo.GridName + @"\P" + //格子号
                                         picInfo.PhotoId + @"\O" + //照片号
                                         picInfo.OrderProductId + @"\" + //产品号
                                         picInfo.Remark + "\\" +
                                         picInfo.OrderProductName + @"\" +
                                         picInfo.ShopName + @"\B" +
                                         board.BoardBaseInfo.BoardId + @"\" +
                                         picInfo.Width.ToString("0.00") + "*" +
                                         picInfo.Height.ToString("0.00") + "(" +
                                         (picInfo.Width*2.54).ToString("0.00") + "*" +
                                         (picInfo.Height*2.54).ToString("0.00") + @")\" +
                                         DateTime.Now.ToString();
                            }
                            //barStr = barStr.Substring(barStr.IndexOf("P"));
                            //////processor.Draw3dText(gText,
                            //////                    barStr,
                            //////                    rcFont,
                            //////                    SpecialEffectsTextStyle.Normal,
                            //////                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                            //////                    0, /* horizontal  shadow position */
                            //////                    0, /* vertical shadow position */
                            //////                    FontColor,/* text color, blue */
                            //////                    Color.White,/* shadow color, black */
                            //////                    Color.White, /* border color, white */
                            //////                    textFont,
                            //////                    null);
                            barStr = barStr.Trim('\\').Trim().Trim('\\');
                            //自使用字号
                            if (smallPhotosize < (float) barcodeImageTemp.Width/barcodeImageTemp.XResolution)
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;

                                gText.DrawString(barStr, textFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            else
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;
                                gText.DrawString(barStr, textSmallFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            ColorResolutionCommand gTextCommandommand =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            gTextCommandommand.Run(barcodeImageTemp);

                            gText.Dispose();
                            ColorImgBlock.Dispose(); //释放色块的资源

                            #endregion

                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombinPicAndBarcode(picInfo, ref barcodeImageTemp, ref smallPicImage, ref midImageTmp);

                            #endregion

                        }
                        else //无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                smallPicImage.Width,
                                smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd |
                                               CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }

                        #endregion

                        UPTLab("给中间图画边框");
                        ///midImageTmp中间图

                        //midImageTmp.AddBorderToRegion(0, 0, new RasterColor(Color.Black), new RasterColor(Color.Black), new RasterColor(Color.Black), RasterRegionCombineMode.Set);


                        #region //给中间图画边框

                        if (IsPrintPhotoLine)
                        {
                            DrowBordLine(ref midImageTmp);
                        }

                        #endregion


                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }


                        UPTLab("将中间图贴在大图上");
                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                            pointX + offsetW, //在大图上的坐标
                            pointY,
                            midImageTmp.Width, //长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);

                        //计算裁切尺寸

                        PhotoPoint photoP = new PhotoPoint();

                        photoP.X = board.BoardBaseInfo.PixHeight - (pointY + midImageTmp.Height);
                        photoP.Y = pointX;
                        photoP.Width = midImageTmp.Height;
                        photoP.Height = midImageTmp.Width;
                        listPhotoInfoForCut.Add(photoP);
                        if (XExcursion > photoP.X)
                        {
                            XExcursion = photoP.X; ///居中偏移量
                        }


                        //将中间图贴在大图上
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();

                        UPTPgro(board.ListPhotos.Count, i++); //进度条
                        //this.Invoke(dlUpProgress, new int[] { board.ListPhotos.Count, ++i });
                        UPTLab("添加小图成功:" + picInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {

                        errText = picInfo.PicPath;
                        throw ex;
                    }

                }
                UPTLab("所有小图生成成功");

                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;
                //判断目录是否存在
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }
                int qipanHeight = Convert.ToInt32(0.5/2.54*board.BoardBaseInfo.DPI);



                //写入文件
                StringBuilder sbWriter = new StringBuilder();
                sbWriter.AppendLine(
                    (((double) board.BoardBaseInfo.PixHeight/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    (((double) board.BoardBaseInfo.PixWidth/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    board.BoardBaseInfo.PrintName);
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {
                    string mmX = (((double) pp.X/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmy = (((double) pp.Y/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmWidth = (((double) pp.Width/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmheight = (((double) pp.Height/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    sbWriter.AppendLine(strWriter);

                }

                string FileName = destFileName.Substring(0, destFileName.LastIndexOf("@")) + ".txt";
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                CommFile.WrtieTextEn(sbWriter, FileName);
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;


                if (board.BoardBaseInfo.Sharpen > 0) //如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    Leadtools.ImageProcessing.Effects.SharpenCommand command =
                        new Leadtools.ImageProcessing.Effects.SharpenCommand();
                    command.Sharpness = board.BoardBaseInfo.Sharpen;
                    command.Run(destImage);
                }


                UPTLab("正在保存大图...");

                if (Settings.Default.AddIccByPs) //需要用PS加载ICC
                {
                    if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                    {
                        codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                    }
                    else
                    {
                        codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                    }

                }
                else //用LEADTOOLS加载ICC
                {
                    //处理旋转的问题
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    UPTLab("正在竖向旋转90度...");
                    //    if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                    //    {
                    //        try
                    //        {
                    //            File.Delete(Application.StartupPath + "\\tem.jpg");
                    //        }
                    //        catch { }

                    //        codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                    //        PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                    //        myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);
                    //        destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                    //        File.Delete(Application.StartupPath + "\\temBig.jpg");
                    //    }
                    //    else
                    //    {
                    //        RotateCommand rc = new RotateCommand();
                    //        rc.Angle = 90 * 100;
                    //        rc.FillColor = new RasterColor(255, 255, 255);
                    //        rc.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                    //        rc.Run(destImage);
                    //    }

                    //}

                    switch (PicFormat)
                    {
                        case 0:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }

                    #region//指定转换配置文件(不通过ps加载ICC时用)

                    string colorSpace = Properties.Settings.Default.ColorSpace;
                    bool setColorSpace = Properties.Settings.Default.SetColorSpace;
                    string fname = Application.StartupPath + "\\SetSpaceTem.jpg";

                    int intRatate = 0;
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    intRatate = 90;
                    //}
                    string strResult = string.Empty, strPicFormat;
                    if (setColorSpace)
                    {
                        try
                        {
                            File.Delete(Application.StartupPath + "\\SetSpaceTem.jpg");
                        }
                        catch
                        {
                        }
                        codecs.Save(destImage, Application.StartupPath + "\\SetSpaceTem.jpg", RasterImageFormat.Jpeg, 24);
                        //PSICC.ClassIccClass myclass = new PSICC.ClassIccClass();

                        //switch (PicFormat)
                        //{
                        //    case 0: strPicFormat = "JPEG"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref  intRatate);

                        //        break;
                        //    case 1: strPicFormat = "TIFF"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref intRatate);
                        //        break;
                        //}

                        psApp.AddICC(colorSpace, fname, destFileName);

                        if (strResult == destFileName)
                        {
                            UPTLab("成功转换配置文件:" + colorSpace);
                        }
                        else
                        {
                            //加载ICC失败
                            UPTLab("转换配置文件失败!" + strResult);
                            throw new Exception("转换配置文件失败!" + strResult);
                        }
                    }

                    #endregion
                }



                #region //写入ICC文件

                UPTLab("正在加载ICC文件..." + board.BoardBaseInfo.IccPath);
                if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                {
                    if (Properties.Settings.Default.AddIccByPs) //需要用PS加载ICC
                    {
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName =
                                board.BoardBaseInfo.IccPath.Substring(board.BoardBaseInfo.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName); //如果以前生成过图片，则删除已生成的
                            }
                            catch
                            {
                            }

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            string strResult = string.Empty, strPicFormat;
                            string strInputIcc = Settings.Default.ColorSpace;
                            //string strInputIcc = "ColorMatch RGB";
                            //string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90竖版生成后不需要旋转
                            //    intRatate = -90;

                            //switch (PicFormat)
                            //{
                            //    case 0: strPicFormat = "JPEG"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref  intRatate);

                            //        break;
                            //    case 1: strPicFormat = "TIFF"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                            //        break;
                            //}

                            psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                //加载ICC失败
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件失败!" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath); //删除保存到C盘的零时的图片文件
                            }
                            catch
                            {
                            }
                        }
                    }
                    else //用LEADTOOLS加载ICC
                    {
                        if (File.Exists(board.BoardBaseInfo.IccPath))
                        {
                            try
                            {
                                IccProfileExtended iccProfile = new IccProfileExtended(board.BoardBaseInfo.IccPath);
                                iccProfile.WriteToImage(destFileName, destImage.PageCount);

                            }
                            catch (Exception ef)
                            {
                                UPTLab("加载ICC文件错误:" + ef.Message);
                                throw new Exception("加载ICC文件错误" + ef.Message);
                            }
                        }
                    }
                }

                #endregion

                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0); //进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                _mainBLL.MakeBigPicSusscess(board.BoardBaseInfo.BoardId, destFileName); //生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");
            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //errText = "生成大图错误"+ex1.Message;
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int) EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }

        /// <summary>
        /// 横向排横向生成裁切标记在后面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2HCutAfterPic(BoardInfo_ProductBigPic board)
        {

            //var p1 = mai.CreateMarkPictureToFile(7620, 254,@"c:\1234.bmp", "123", "abc");

            int i = 0; //当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath; //最终大图的保存路径
            int boardPixWidth = board.BoardBaseInfo.PixWidth; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.PixHeight; //大图的高,相素
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();
            string errText = "";
            int XExcursion = 0;
            if (PicFormat < 0)
            {
                PicFormat = 0;
            }
            XExcursion = boardPixWidth;



            if (PicFormat == 1)
            {
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }

            UPTLab("正在生成：" + destFileName);
            //this.Invoke(dlUpProgress, new int[] { 0, 0 });
            UPTPgro(0, 0);
            //生成裁切标记



            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();

                string aaa =
                    mai.CreateMarkPictureToFile(
                        Convert.ToInt32((double) BoardPixHeight/board.BoardBaseInfo.DPI*2.54*100),
                        board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp",
                        board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                //旋转270条码
                //旋转裁切标记
                RotateCommand rcSmall = new RotateCommand(); //旋转条码图片               
                rcSmall.Angle = 90*100;
                rcSmall.FillColor = new RasterColor(255, 255, 255);
                rcSmall.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
                rcSmall.Run(smallTop);

                int offsetW = smallTop.Width;

                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Tiled,
                    boardPixWidth + offsetW,
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                FillCommand fcommand = new FillCommand();

                fcommand.Color = new RasterColor(Settings.Default.BackColor.R, Settings.Default.BackColor.G,
                    Settings.Default.BackColor.B);
                fcommand.Run(destImage);
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;
                //添加裁切信息

                CombineFastCommand cfctop = new CombineFastCommand();
                cfctop.DestinationRectangle = new Rectangle(boardPixWidth, 0, smallTop.Width, smallTop.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(smallTop);


                UPTLab("生大大图框架成功");
                foreach (var picInfo in board.ListPhotos)
                {
                    if (picInfo.labelWidth != 0)
                    {
                        BARCODEHEIGHT = picInfo.labelWidth;
                    }
                    int temp = 0;
                    //temp=picInfo.PixHeight;
                    //picInfo.PixHeight = picInfo.PixWidth;
                    //picInfo.PixWidth = temp;


                    //picInfo.IsWhirl = !picInfo.IsWhirl;
                    UPTLab("正在添加小图:" + picInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上

                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.PicPath))
                        {
                            throw new Exception("文件不存在：" + picInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board); //小图片
                        DrowBordLine(ref smallPicImage, Color.Green);
                        RasterImage midImageTmp = CreateMidImg(picInfo, board); //带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");

                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.BarCodeStatus != 2) //有条码
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board); //条码图片的临时图片

                            RasterImage ColorImgBlock = GetProductColorBlock(picInfo.OrderProductId); //色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");

                            #region//条码信息有限处理

                            Graphics gBarcode = barcodeImageTemp.CreateGdiPlusGraphics().Graphics; //用来打印条码和文字
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            //int recX = ColorImgBlock.Width + 10, recY = 0;
                            int recX = ColorImgBlock.Width, recY = 0; //当前操作在条码图片上的位置

                            SizeF sizeF = gFont.MeasureString("*" + picInfo.PhotoId.ToString() + "*", textBarFont);
                            //sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution;
                            BARCODEWIDTH = Convert.ToInt32(sizeF.Width/gFont.DpiX*barcodeImageTemp.XResolution) + 10;
                                //条码的宽度

                            bool isPrintBarCode = false; //是否要打印条码
                            if (Settings.Default.SmallSizeToPrintBarCode <= 0)
                            {
                                isPrintBarCode = BARCODEWIDTH + 100 <= barcodeImageTemp.Width;
                            }
                            else
                            {
                                isPrintBarCode = barcodeImageTemp.Width >
                                                 Settings.Default.SmallSizeToPrintBarCode*board.BoardBaseInfo.DPI;
                            }

                            //if (BARCODEWIDTH + 100 <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (isPrintBarCode) //如果照片的宽度大于5寸才打印条码,目的是为了显示更多的有用的信息
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIGHT);


                                gBarcode.DrawString("*" + picInfo.PhotoId.ToString() + "*", textBarFont, Brushes.Black,
                                    recX, recY);
                                recX += BARCODEWIDTH;


                            }
                            gBarcode.Dispose();
                            ColorResolutionCommand command =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            command.Run(barcodeImageTemp);

                            #endregion

                            UPTLab("粘贴色块");

                            #region//粘贴色块

                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                barcodeImageTemp.Width,
                                barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd |
                                                CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);

                            #endregion

                            UPTLab("生成条码及文字");

                            #region 文字信息



                            //写其文字信息
                            Graphics gText = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;
                            //recX += 10;
                            Rectangle rcFont = new Rectangle(recX, 0, barcodeImageTemp.Width - recX, BARCODEHEIGHT);

                            string barStr = GetBarCodeStringByCutsom(picInfo, board);
                            if (string.IsNullOrEmpty(barStr))
                            {
                                barStr = picInfo.GridName + @"\P" + //格子号
                                         picInfo.PhotoId + @"\O" + //照片号
                                         picInfo.OrderProductId + @"\" + //产品号
                                         picInfo.Remark + "\\" +
                                         picInfo.OrderProductName + @"\" +
                                         picInfo.ShopName + @"\B" +
                                         board.BoardBaseInfo.BoardId + @"\" +
                                         picInfo.Width.ToString("0.00") + "*" +
                                         picInfo.Height.ToString("0.00") + "(" +
                                         (picInfo.Width*2.54).ToString("0.00") + "*" +
                                         (picInfo.Height*2.54).ToString("0.00") + @")\" +
                                         DateTime.Now.ToString();
                            }
                            //barStr = barStr.Substring(barStr.IndexOf("P"));
                            //////processor.Draw3dText(gText,
                            //////                    barStr,
                            //////                    rcFont,
                            //////                    SpecialEffectsTextStyle.Normal,
                            //////                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                            //////                    0, /* horizontal  shadow position */
                            //////                    0, /* vertical shadow position */
                            //////                    FontColor,/* text color, blue */
                            //////                    Color.White,/* shadow color, black */
                            //////                    Color.White, /* border color, white */
                            //////                    textFont,
                            //////                    null);
                            //自使用字号
                            barStr = barStr.Trim('\\').Trim().Trim('\\');
                            if (smallPhotosize < (float) barcodeImageTemp.Width/barcodeImageTemp.XResolution)
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;

                                gText.DrawString(barStr, textFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            else
                            {
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Near;
                                sf.LineAlignment = StringAlignment.Near;
                                gText.DrawString(barStr, textSmallFont, new SolidBrush(FontColor), rcFont, sf);
                            }
                            ColorResolutionCommand gTextCommandommand =
                                new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            gTextCommandommand.Run(barcodeImageTemp);

                            gText.Dispose();
                            ColorImgBlock.Dispose(); //释放色块的资源

                            #endregion


                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombinPicAndBarcode(picInfo, ref barcodeImageTemp, ref smallPicImage, ref midImageTmp);


                            #endregion

                        }
                        else //无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                0,
                                0,
                                smallPicImage.Width,
                                smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd |
                                               CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }

                        #endregion

                        UPTLab("给中间图画边框");
                        ///midImageTmp中间图

                        //midImageTmp.AddBorderToRegion(0, 0, new RasterColor(Color.Black), new RasterColor(Color.Black), new RasterColor(Color.Black), RasterRegionCombineMode.Set);


                        #region //给中间图画边框

                        if (IsPrintPhotoLine)
                        {
                            DrowBordLine(ref midImageTmp);
                        }

                        #endregion


                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }


                        UPTLab("将中间图贴在大图上");
                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                            pointX, //在大图上的坐标
                            pointY,
                            midImageTmp.Width, //长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);

                        //计算裁切尺寸

                        PhotoPoint photoP = new PhotoPoint();
                        photoP.X = pointY;
                        photoP.Y = board.BoardBaseInfo.PixWidth - (pointX + midImageTmp.Width);
                        if (photoP.Y < 0)
                        {
                            photoP.Y = 0;
                        }
                        photoP.Width = midImageTmp.Height;
                        photoP.Height = midImageTmp.Width;
                        listPhotoInfoForCut.Add(photoP);
                        if (XExcursion > photoP.X)
                        {
                            XExcursion = photoP.X; ///居中偏移量
                        }


                        //将中间图贴在大图上
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();

                        UPTPgro(board.ListPhotos.Count, i++); //进度条
                        //this.Invoke(dlUpProgress, new int[] { board.ListPhotos.Count, ++i });
                        UPTLab("添加小图成功:" + picInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {

                        errText = picInfo.PicPath;
                        throw ex;
                    }

                }
                UPTLab("所有小图生成成功");

                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;
                //判断目录是否存在
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }
                int qipanHeight = Convert.ToInt32(0.5/2.54*board.BoardBaseInfo.DPI);



                //写入文件
                StringBuilder sbWriter = new StringBuilder();
                sbWriter.AppendLine(
                    (((double) board.BoardBaseInfo.PixHeight/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    (((double) board.BoardBaseInfo.PixWidth/board.BoardBaseInfo.DPI*2.54*100)).ToString("0") + "," +
                    board.BoardBaseInfo.PrintName);
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {
                    string mmX = (((double) pp.X/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmy = (((double) pp.Y/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmWidth = (((double) pp.Width/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string mmheight = (((double) pp.Height/board.BoardBaseInfo.DPI*2.54*100)).ToString("0");
                    string strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    sbWriter.AppendLine(strWriter);

                }

                string FileName = destFileName.Substring(0, destFileName.LastIndexOf("@")) + ".txt";
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                CommFile.WrtieTextEn(sbWriter, FileName);
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;


                if (board.BoardBaseInfo.Sharpen > 0) //如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    Leadtools.ImageProcessing.Effects.SharpenCommand command =
                        new Leadtools.ImageProcessing.Effects.SharpenCommand();
                    command.Sharpness = board.BoardBaseInfo.Sharpen;
                    command.Run(destImage);
                }


                UPTLab("正在保存大图...");

                if (Settings.Default.AddIccByPs) //需要用PS加载ICC
                {
                    if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                    {
                        codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                    }
                    else
                    {
                        codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                    }

                }
                else //用LEADTOOLS加载ICC
                {
                    //处理旋转的问题
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    UPTLab("正在竖向旋转90度...");
                    //    if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                    //    {
                    //        try
                    //        {
                    //            File.Delete(Application.StartupPath + "\\tem.jpg");
                    //        }
                    //        catch { }

                    //        codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                    //        PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                    //        myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);
                    //        destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                    //        File.Delete(Application.StartupPath + "\\temBig.jpg");
                    //    }
                    //    else
                    //    {
                    //        RotateCommand rc = new RotateCommand();
                    //        rc.Angle = 90 * 100;
                    //        rc.FillColor = new RasterColor(255, 255, 255);
                    //        rc.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                    //        rc.Run(destImage);
                    //    }

                    //}

                    switch (PicFormat)
                    {
                        case 0:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }

                    #region//指定转换配置文件(不通过ps加载ICC时用)

                    string colorSpace = Properties.Settings.Default.ColorSpace;
                    bool setColorSpace = Properties.Settings.Default.SetColorSpace;
                    string fname = Application.StartupPath + "\\SetSpaceTem.jpg";

                    int intRatate = 0;
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    intRatate = 90;
                    //}
                    string strResult = string.Empty, strPicFormat;
                    if (setColorSpace)
                    {
                        try
                        {
                            File.Delete(Application.StartupPath + "\\SetSpaceTem.jpg");
                        }
                        catch
                        {
                        }
                        codecs.Save(destImage, Application.StartupPath + "\\SetSpaceTem.jpg", RasterImageFormat.Jpeg, 24);
                        //PSICC.ClassIccClass myclass = new PSICC.ClassIccClass();

                        //switch (PicFormat)
                        //{
                        //    case 0: strPicFormat = "JPEG"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref  intRatate);

                        //        break;
                        //    case 1: strPicFormat = "TIFF"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref intRatate);
                        //        break;
                        //}

                        psApp.AddICC(colorSpace, fname, destFileName);

                        if (strResult == destFileName)
                        {
                            UPTLab("成功转换配置文件:" + colorSpace);
                        }
                        else
                        {
                            //加载ICC失败
                            UPTLab("转换配置文件失败!" + strResult);
                            throw new Exception("转换配置文件失败!" + strResult);
                        }
                    }

                    #endregion
                }



                #region //写入ICC文件

                UPTLab("正在加载ICC文件..." + board.BoardBaseInfo.IccPath);
                if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                {
                    if (Properties.Settings.Default.AddIccByPs) //需要用PS加载ICC
                    {
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName =
                                board.BoardBaseInfo.IccPath.Substring(board.BoardBaseInfo.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName); //如果以前生成过图片，则删除已生成的
                            }
                            catch
                            {
                            }

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            string strResult = string.Empty, strPicFormat;
                            string strInputIcc = Settings.Default.ColorSpace;
                            //string strInputIcc = "ColorMatch RGB";
                            //string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90竖版生成后不需要旋转
                            //    intRatate = -90;

                            //switch (PicFormat)
                            //{
                            //    case 0: strPicFormat = "JPEG"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref  intRatate);

                            //        break;
                            //    case 1: strPicFormat = "TIFF"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                            //        break;
                            //}

                            psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                //加载ICC失败
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件失败!" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath); //删除保存到C盘的零时的图片文件
                            }
                            catch
                            {
                            }
                        }
                    }
                    else //用LEADTOOLS加载ICC
                    {
                        if (File.Exists(board.BoardBaseInfo.IccPath))
                        {
                            try
                            {
                                IccProfileExtended iccProfile = new IccProfileExtended(board.BoardBaseInfo.IccPath);
                                iccProfile.WriteToImage(destFileName, destImage.PageCount);

                            }
                            catch (Exception ef)
                            {
                                UPTLab("加载ICC文件错误:" + ef.Message);
                                throw new Exception("加载ICC文件错误" + ef.Message);
                            }
                        }

                    }
                }

                #endregion

                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0); //进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                _mainBLL.MakeBigPicSusscess(board.BoardBaseInfo.BoardId, destFileName); //生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");
            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //errText = "生成大图错误"+ex1.Message;
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int) EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }

        #endregion


        int whichIcon = 1;

        System.ComponentModel.ComponentResourceManager resources =
            new System.ComponentModel.ComponentResourceManager(typeof(MINERP.NewProductBigPic.Properties.Resources));

        private void timerNotifyIcon_Tick(object sender, EventArgs e)
        {
            //this.timerNotifyIcon.Enabled = false;
            //if (timerFlag == false)
            //{
            //    if (whichIcon == 1)
            //    {
            //        this.notifyIcon1.Icon = (System.Drawing.Icon)(resources.GetObject("2"));
            //        whichIcon = 2;
            //    }
            //    else
            //    {
            //        if (whichIcon == 2)
            //        {
            //            this.notifyIcon1.Icon = (System.Drawing.Icon)((resources.GetObject("1")));
            //            whichIcon = 1;
            //        }
            //    }
            //}
            //else
            //{
            //    this.notifyIcon1.Icon = (System.Drawing.Icon)((resources.GetObject("1")));
            //    whichIcon = 1;
            //}
            //this.timerNotifyIcon.Enabled = true;
        }

        private string DoubleToString(double inDouble)
        {
            double temp = Math.Round(inDouble, MidpointRounding.AwayFromZero);
            return temp.ToString();
        }

        #region help methods

        /// <summary>
        /// 根据用户自定义的条码信息得到条码的文本信息
        /// </summary>
        /// <returns></returns>
        private string GetBarCodeStringByCutsom(PhotoInfo_ProductBigPic picInfo, BoardInfo_ProductBigPic board)
        {
            /*
              picInfo.GridName + @"\P" +//格子号
                                                 picInfo.PhotoId + @"\O" +//照片号
                                                 picInfo.OrderProductId + @"\" +//产品号
                                                 picInfo.Remark + "\\" +
                                //picInfo.CtmName + @"\" +//客人名
                                //picInfo.PhotoName.Substring(picInfo.PhotoName.IndexOf("_") + 1).Substring(4) + @"\" +//照片名                                                
                                                 picInfo.OrderProductName + @"\" +
                                                 picInfo.ShopName + @"\B" +
                                                 board.BoardBaseInfo.BoardId + @"\" +
                                                 picInfo.Width.ToString("0.00") + "*" +
                                                 picInfo.Height.ToString("0.00") + "(" +
                                                 (picInfo.Width * 2.54).ToString("0.00") + "*" +
                                                 (picInfo.Height * 2.54).ToString("0.00") + @")\" +
                                                 DateTime.Now.ToString(),
             */

            List<MINERP.NewProductBigPic.FrmSettings.BarSerInfo> barList = FrmSettings.GetInitil();
            //如果照片的上一层文件夹名字为输出，则备注去照片名字，否则去照片的上一层文件夹名字
            string[] ArrayRemark = picInfo.Remark.Split('\\');
            string remark = ArrayRemark[0].Trim() == "输出" ? ArrayRemark[1] : ArrayRemark[0];
            StringBuilder sbR = new StringBuilder();

            foreach (var barSet in barList)
            {
                if (!barSet.IsPrint)
                {
                    continue;
                }
                switch (barSet.Code)
                {
                    case "GN":
                        sbR.Append(@"\" + picInfo.GridName); //格子号
                        break;
                    case "PID":
                        sbR.Append(@"\P" + picInfo.PhotoId); //照片号
                        break;
                    case "OID":
                        sbR.Append(@"\O" + picInfo.OrderProductId); //产品号
                        break;
                    //case "PREMARK": sbR.Append(@"\" + remark);//照片备注
                    case "PREMARK":
                        sbR.Append(@"\" + picInfo.Remark); //照片备注
                        break;
                    case "ONAME":
                        sbR.Append(@"\" + picInfo.OrderProductName); //产品名称
                        break;
                    case "SNAME":
                        sbR.Append(@"\" + picInfo.ShopName); //商户名称
                        break;
                    case "BID":
                        sbR.Append(@"\" + board.BoardBaseInfo.BoardId); //大板号
                        break;
                    case "PSIZE":
                        sbR.Append(@"\" +
                                   // picInfo.Width.ToString("0.00") + "*" +picInfo.Height.ToString("0.00") +
                                   "(" + (picInfo.Width*2.54).ToString("0.00") + "*" +
                                   (picInfo.Height*2.54).ToString("0.00") + ")"); //照片尺寸信息
                        break;
                    case "DATE":
                        sbR.Append(@"\" + DateTime.Now.ToString("yy-MM-dd HH:mm:ss")); //生成时间
                        break;
                    case "PNAME":
                        sbR.Append(@"\" + picInfo.PhotoName); //照片名称
                        break;
                    case "CName":
                        sbR.Append(@"\" + picInfo.CtmName); //客人名称
                        break;
                    case "NumInOrder":
                        sbR.Append(@"\总" + picInfo.NumInOrder+"张"); //总张数

                        break;
                    default: //空
                        break;
                }
            }
            if (!string.IsNullOrEmpty(picInfo.TiaoseNo))
            {
                return "T" + picInfo.TiaoseNo + "\\" + sbR.ToString();
            }
            else
            {
                return sbR.ToString();
            }
        }


        //设置窗体的大小尺寸
        private void SetSize()
        {
            if (_isMore == true)
            {
                this.Width = 546;
                this.Height = 437;
                //this.textBox1.Visible = true;
            }
            else
            {
                this.Width = 546;
                this.Height = 140;
                //this.textBox1.Visible = false;
            }
        }

        //设置窗体的位置
        private void SetLocation()
        {
            Rectangle rect = Screen.PrimaryScreen.WorkingArea;
            this.Location = new Point(rect.Width - this.Width, rect.Height - this.Height);
        }

        private void SetTimer()
        {
            this.timer1.Enabled = true;
            this.timer1.Interval = 3000;

            this.timerNotifyIcon.Enabled = true;
            this.timerNotifyIcon.Interval = 800;
        }

        private Hashtable ColorList = new Hashtable();
        private const int COLORSETUP = 10;
        private int colorIndex = 1;
        private int MinOrderProductId = 0; //放在LIST中最小的那个ORDERPRODUCTID，当hashtableLIST数量达到20个时就删除最小的那个

        RasterColor Color1 = new RasterColor(0, 0, 0);
        RasterColor Color2 = new RasterColor(150, 150, 150);
        RasterColor Color3 = new RasterColor(130, 0, 20);
        RasterColor Color4 = new RasterColor(242, 24, 38);
        RasterColor Color5 = new RasterColor(255, 242, 5);
        RasterColor Color6 = new RasterColor(28, 128, 79);
        RasterColor Color7 = new RasterColor(0, 163, 231);

        RasterColor Color8 = new RasterColor(63, 70, 209);
        RasterColor Color9 = new RasterColor(255, 90, 255);
        RasterColor Color10 = new RasterColor(255, 255, 25);
        RasterColor Color11 = new RasterColor(200, 160, 255);
        RasterColor Color12 = new RasterColor(184, 127, 84);
        RasterColor Color13 = new RasterColor(254, 170, 202);
        RasterColor Color14 = new RasterColor(254, 200, 0);

        RasterColor Color15 = new RasterColor(240, 228, 173);
        RasterColor Color16 = new RasterColor(177, 231, 30);
        RasterColor Color17 = new RasterColor(154, 217, 233);
        RasterColor Color18 = new RasterColor(111, 147, 191);
        RasterColor Color19 = new RasterColor(202, 189, 243);
        RasterColor Color20 = new RasterColor(128, 0, 60);
        RasterColor Color21 = new RasterColor(79, 81, 81);

        RasterColor Color22 = new RasterColor(0, 127, 0);
        RasterColor Color23 = new RasterColor(0, 255, 0);
        RasterColor Color24 = new RasterColor(255, 0, 127);
        RasterColor Color25 = new RasterColor(160, 71, 196);
        RasterColor Color26 = new RasterColor(128, 128, 0);
        RasterColor Color27 = new RasterColor(0, 64, 127);
        RasterColor Color28 = new RasterColor(127, 254, 254);
        RasterColor Color29 = new RasterColor(128, 0, 128);
        RasterColor Color30 = new RasterColor(255, 0, 255);

        private RasterImage GetColorBlock(int orderProductId) //根据产品得到相应的色块
        {
            if (orderProductId < MinOrderProductId)
            {
                MinOrderProductId = orderProductId;
            }
            RasterColor curColor;
            if (ColorList.ContainsKey(orderProductId))
            {
                curColor = (RasterColor) ColorList[orderProductId];
            }
            else
            {

                if (colorIndex >= 14)
                {
                    ColorList.Remove(MinOrderProductId);
                    colorIndex = 1;
                    curColor = Color1;
                }
                else
                {
                    #region 设定颜色

                    switch (colorIndex)
                    {
                        case 2:
                            curColor = Color2;
                            break;
                        case 3:
                            curColor = Color3;
                            break;
                        case 4:
                            curColor = Color4;
                            break;
                        case 5:
                            curColor = Color5;
                            break;
                        case 6:
                            curColor = Color6;
                            break;
                        case 7:
                            curColor = Color7;
                            break;
                        case 8:
                            curColor = Color8;
                            break;
                        case 9:
                            curColor = Color9;
                            break;
                        case 10:
                            curColor = Color10;
                            break;
                        case 11:
                            curColor = Color11;
                            break;
                        case 12:
                            curColor = Color12;
                            break;
                        case 13:
                            curColor = Color13;
                            break;
                        case 14:
                            curColor = Color14;
                            break;
                        default:
                            curColor = Color1;
                            break;
                    }

                    #endregion

                    colorIndex++;
                }

                ColorList.Add(orderProductId, curColor);
            }

            RasterImage destImage = new RasterImage(
                RasterMemoryFlags.Conventional,
                50,
                25,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);

            FillCommand fcommand = new FillCommand();
            fcommand.Color = curColor;
            fcommand.Run(destImage);

            return destImage;
        }

        //const string sharP1 = "▲";
        //const string sharP2 = "◆";
        //const string sharP3 = "■";
        //const string sharP4 = "★";
        //const string sharP5 = "▼";
        //const string sharP6 = "✚";
        //const string sharP7 = "❤";
        //const string sharP8 = "✿";
        //const string sharP9 = "●";
        //const string sharP10 = "☽";
        private string[] SharpArr = {"▲", "◆", "■", "★", "▼", "✚", "✚", "❤", "✿", "●", "☽"};

        private RasterImage GetProductColorBlock(int orderProductId) //根据产品得到相应的色块
        {
            RasterImage destImage = new RasterImage(
                RasterMemoryFlags.Conventional,
                50,
                25,
                24,
                RasterByteOrder.Bgr,
                RasterViewPerspective.BottomLeft,
                null,
                IntPtr.Zero,
                0);

            FillCommand fcommand = new FillCommand();
            RasterColor color = GetColor(orderProductId);
            fcommand.Color = color;
            fcommand.Run(destImage);
            //创建一个小白色块
            RasterImage frontImage = new RasterImage(
               RasterMemoryFlags.Conventional,
               25,
               25,
               24,
               RasterByteOrder.Bgr,
               RasterViewPerspective.BottomLeft,
               null,
               IntPtr.Zero,
               0);
            //FillCommand fcommand = new FillCommand();
            RasterColor colorWithe = new RasterColor(255,255,255);
            fcommand.Color = colorWithe;
            fcommand.Run(frontImage);

            CombineFastCommand combineFastCommand=new CombineFastCommand();
            combineFastCommand.DestinationImage = destImage;
            combineFastCommand.DestinationRectangle = new Rectangle(0, 0, frontImage.Width, frontImage.Height);
            combineFastCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            combineFastCommand.Run(frontImage);

            DrawSharp(orderProductId, Color.FromArgb(0, color.R, color.G, color.B), destImage);
            return destImage;
        }

        void DrawSharp(int orderProductid, Color inColor, RasterImage destImage)
        {
            try
            {

                using (RasterImageGdiPlusGraphicsContainer container = destImage.CreateGdiPlusGraphics())
                {
                    container.Graphics.SmoothingMode = SmoothingMode.HighQuality;

                    Font font1 = new Font("Arial", 16);

                    int gray = (int) (inColor.R*0.3 + inColor.G*0.59 + inColor.B*0.11);

                    Brush br = new SolidBrush(Color.FromArgb(255, 0, 0, 0));
                    int xuhao = orderProductid/10%10;
                    string sharp = SharpArr[xuhao];
                    StringFormat stringFormat=new StringFormat();
                    stringFormat.Alignment = StringAlignment.Near;
                    stringFormat.LineAlignment = StringAlignment.Near;
                    stringFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;
                    container.Graphics.DrawString(sharp, font1, br, -10, -3, stringFormat);
                }
                //using (Graphics g = destImage.CreateGdiPlusGraphics().Graphics)
                //{
                //    //用来打印条码和文字
                //    g.SmoothingMode = SmoothingMode.None;
                //    SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                //    StringFormat textFormat = new StringFormat();
                //    textFormat.Alignment = StringAlignment.Near;
                //    textFormat.LineAlignment = StringAlignment.Center;
                //    textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;
                //    gFont.PageUnit = GraphicsUnit.Pixel;
                //    int xuhao = orderProductid/10%10;
                //    string sharp = SharpArr[xuhao];
                //    int gray = (int) (inColor.R*0.3 + inColor.G*0.59 + inColor.B*0.11);
                //    Rectangle rcFont = new Rectangle(2, 2, destImage.Width - 2, destImage.Height - 2);
                //    g.DrawString(sharp, textFont, new SolidBrush(Color.FromArgb(255, 0, 0, 0)), rcFont, textFormat);
                //}

            }
            catch (Exception)
            {

                throw;
            }
        }

        #endregion
        public RasterColor GetColor(int inNum)
        {
            int FirstNum = inNum % 1000 / 100;
            int SecondNum = inNum % 100 / 10;
            int ThirdNum = inNum % 10;
            int ColorRed = 0;
            int ColorGreen = 0;
            int ColorBlue = 0;

            if (inNum % 6 == 0)
            {
                ColorGreen = Convert.ToInt32((FirstNum + 6) * 10 + Math.Pow(10 - FirstNum, FirstNum)) % 255;
                ColorRed = Convert.ToInt32((SecondNum + 6) * 10 + Math.Pow(10 - SecondNum, (SecondNum + 2))) % 255;
                ColorBlue = Convert.ToInt32((ThirdNum + 6) * 10 + Math.Pow(10 - ThirdNum, (ThirdNum + 3))) % 255;
                ColorGreen = 255 - ColorGreen;
                ColorBlue = 255 - ColorBlue;
            }
            else if (inNum % 4 == 0)
            {
                ColorGreen = Convert.ToInt32((FirstNum + 4) * 10 + Math.Pow(10 - FirstNum, FirstNum)) % 255;
                ColorRed = Convert.ToInt32((SecondNum + 4) * 10 + Math.Pow(10 - SecondNum, (SecondNum + 2))) % 255;
                ColorBlue = Convert.ToInt32((ThirdNum + 4) * 10 + Math.Pow(10 - ThirdNum, (ThirdNum + 3))) % 255;
                ColorBlue = 255 - ColorBlue;
            }
            else if (inNum % 5 == 0)
            {
                ColorGreen = Convert.ToInt32((FirstNum + 5) * 10 + Math.Pow(10 - FirstNum, FirstNum)) % 255;
                ColorRed = Convert.ToInt32((SecondNum + 5) * 10 + Math.Pow(10 - SecondNum, (SecondNum + 2))) % 255;
                ColorBlue = Convert.ToInt32((ThirdNum + 5) * 10 + Math.Pow(10 - ThirdNum, (ThirdNum + 3))) % 255;
                ColorBlue = 255 - ColorBlue;
            }
            else if (inNum % 7 == 0)
            {
                ColorGreen = Convert.ToInt32((FirstNum + 7) * 10 + Math.Pow(10 - FirstNum, FirstNum)) % 255;
                ColorRed = Convert.ToInt32((SecondNum + 7) * 10 + Math.Pow(10 - SecondNum, (SecondNum + 2))) % 255;
                ColorBlue = Convert.ToInt32((ThirdNum + 7) * 10 + Math.Pow(10 - ThirdNum, (ThirdNum + 3))) % 255;
                ColorBlue = 255 - ColorBlue;
                ColorRed = 255 - ColorRed;
                ColorGreen = 255 - ColorGreen;
            }
            else if (inNum % 3 == 0)
            {
                ColorRed = FirstNum;
                ColorGreen = SecondNum;
                ColorBlue = ThirdNum;
                ColorGreen = 255 - ColorGreen;
                ColorRed = 255 - ColorRed;
            }
            else if (inNum % 2 == 0)
            {
                ColorGreen = Convert.ToInt32((FirstNum + 1) * 10 + Math.Pow(10 - FirstNum, FirstNum)) % 255;
                ColorRed = Convert.ToInt32((SecondNum + 2) * 10 + Math.Pow(10 - SecondNum, (SecondNum + 2))) % 255;
                ColorBlue = Convert.ToInt32((ThirdNum + 3) * 10 + Math.Pow(10 - ThirdNum, (ThirdNum + 3))) % 255;
                ColorRed = 255 - ColorRed;
                ColorGreen = 255 - ColorGreen;
            }
            else
            {
                ColorGreen = Math.Abs(Convert.ToInt32((FirstNum - 1) * 11 + Math.Pow(10 - FirstNum, FirstNum)) % 255);
                ColorBlue = Math.Abs(Convert.ToInt32((SecondNum - 2) * 11 + Math.Pow(10 - SecondNum, (SecondNum + 2))) % 255);
                ColorRed = Math.Abs(Convert.ToInt32((ThirdNum - 3) * 11 + Math.Pow(10 - ThirdNum, (ThirdNum + 3))) % 255);
                ColorBlue = 255 - ColorBlue;

            }
            RasterColor color = new RasterColor(ColorRed, ColorGreen, ColorBlue);
            return color;
        }
        private RasterImage GetColorBlockNew(int orderProductId)//根据产品得到相应的色块
        {

            RasterColor curColor;
            colorIndex = orderProductId % 30;
            #region 设定颜色
            switch (colorIndex)
            {
                case 1:
                    curColor = Color1;
                    break;
                case 2: curColor = Color2;
                    break;
                case 3: curColor = Color3;
                    break;
                case 4: curColor = Color4;
                    break;
                case 5: curColor = Color5;
                    break;
                case 6: curColor = Color6;
                    break;
                case 7: curColor = Color7;
                    break;
                case 8: curColor = Color8;
                    break;
                case 9: curColor = Color9;
                    break;
                case 10: curColor = Color10;
                    break;
                case 11: curColor = Color11;
                    break;
                case 12: curColor = Color12;
                    break;
                case 13: curColor = Color13;
                    break;
                case 14: curColor = Color14;
                    break;
                case 15: curColor = Color15;
                    break;
                case 16: curColor = Color16;
                    break;
                case 17: curColor = Color17;
                    break;
                case 18: curColor = Color18;
                    break;
                case 19: curColor = Color19;
                    break;
                case 20: curColor = Color20;
                    break;
                case 21: curColor = Color21;
                    break;
                case 22: curColor = Color22;
                    break;
                case 23: curColor = Color23;
                    break;
                case 24: curColor = Color24;
                    break;
                case 25: curColor = Color25;
                    break;
                case 26: curColor = Color26;
                    break;
                case 27: curColor = Color27;
                    break;
                case 28: curColor = Color28;
                    break;
                case 29: curColor = Color29;
                    break;
                default: curColor = Color30;
                    break;
            }
            #endregion


            RasterImage destImage1 = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    50,
                    BARCODEHEIGHT,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

            FillCommand fcommand = new FillCommand();
            fcommand.Color = curColor;
            fcommand.Run(destImage1);

            return destImage1;
        }
        private RasterImage CreateColorBlock(int R, int G, int B)//根据颜色创建色块得到相应的色块
        {
            RasterColor curColor = new RasterColor(R, G, B);

            RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    50,
                    25,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

            FillCommand fcommand = new FillCommand();
            fcommand.Color = curColor;
            fcommand.Run(destImage);

            return destImage;
        }
        #region 更新显示、等界面操作
        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
        }

        private delegate void DelegateUPTPgro(int total, int value);
        private void UPTPgro(int total, int value)
        {
            if (!this.InvokeRequired)
            {
                this.progressBar1.Maximum = total;
                this.progressBar1.Value = value;
            }
            else
            {
                this.Invoke(new DelegateUPTPgro(UPTPgro), new object[] { total, value });
            }
        }

        private delegate void DelegateUPTLab(string text);
        private void UPTLab(string text)
        {
            if (!this.InvokeRequired)
            {
                this.label1.Text = text;
            }
            else
            {
                this.BeginInvoke(new DelegateUPTLab(UPTLab), new object[] { text });
            }
        }

        private delegate void DelegateUPTListview(string text);
        private void UPTListview(string text)
        {
            if (!this.InvokeRequired)
            {
                //this.textBox1.Text = this.textBox1.Text + text;
            }
            else
            {
                this.BeginInvoke(new DelegateUPTListview(UPTListview), new object[] { text });
            }
        }

        private delegate void DelegateUPTListView(int baordId, string msg, DateTime time, int status);
        private void UPTListView(int boardId, string msg, DateTime time, int status)
        {
            if (!this.listView1.InvokeRequired)
            {
                ListViewItem lvi = new ListViewItem(boardId.ToString());
                lvi.SubItems.Add(msg);
                lvi.SubItems.Add(time.ToString());
                switch (status)
                {
                    case 1: lvi.BackColor = Color.Green; break;//normal
                    default: lvi.BackColor = Color.Red; break;//error
                }
                listView1.Items.Add(lvi);
            }
            else
            {
                this.BeginInvoke(new DelegateUPTListView(UPTListView), new object[] { boardId, msg, time, status });
            }
        }

        private delegate void DelegateUPlblCount(string msg);
        private void UplblCount(string msg)
        {
            if (!this.InvokeRequired)
            {
                this.label3.Text = msg;
            }
            else
            {
                this.BeginInvoke(new DelegateUPlblCount(UplblCount), new object[] { msg });
            }
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Visible = false;
            e.Cancel = true;
            //notifyIcon1.Visible = false;
        }

        private void 显示主界面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = true;
            }

        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.ExitThread();
        }

        private void cmbPicType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cmbPicType.SelectedIndex != 0)
                PicFormat = this.cmbPicType.SelectedIndex - 1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _isMore = Reverse(_isMore);

            SetSize();
            SetLocation();
        }

        private bool Reverse(bool value)
        {
            if (value == true)
            {
                this.btnMore.Text = "详细信息";
            }
            else
            {
                this.btnMore.Text = "返回";
            }
            return !value;
        }

        private void chkIsStart_CheckedChanged(object sender, EventArgs e)//设置开机自动启动
        {
            //string exeFileName = Application.ExecutablePath;
            //RegistryKey ikey = Registry.LocalMachine;
            //try
            //{
            //    this._xmlOp.Open(Application.StartupPath + @"/Restart.xml");
            //}
            //catch (FileNotFoundException ex)
            //{
            //    MessageBox.Show("未找到系统相关的关件，请重新安装软件！");
            //    return;
            //}


            //RegistryKey Run = ikey.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

            //if (this.chkIsStart.Checked)
            //{
            //    Run.SetValue("生成大图片", exeFileName);
            //    this._xmlOp.UpdateNodeInnerText("Restart", "Yes");
            //    this._xmlOp.UpdateNodeInnerText("PrintName", this._printName);
            //}
            //else
            //{
            //    Run.DeleteValue("生成大图片");
            //    this._xmlOp.UpdateNodeInnerText("Restart", "No");
            //}

            //this._xmlOp.Save();
            //Run.Close();

            //ikey.Close();
        }

        #endregion

        private void button1_Click_1(object sender, EventArgs e)
        {
            //设置条码打出来的字段的顺序

        }

        private void checkBoxBackColorIsGreen_CheckedChanged(object sender, EventArgs e)
        {
            //Settings.Default.BackColor = checkBoxBackColorIsGreen.Checked;
            //Settings.Default.Save();

        }

        private void btnSetting_Click(object sender, EventArgs e)
        {
            FrmSettings frmSet = new FrmSettings();
            frmSet.ShowDialog();
        }

        private void buttonBoardColor_Click(object sender, EventArgs e)
        {
            FrmColorSetting frm = new FrmColorSetting();
            frm.ShowDialog();
        }

    }
    public class PhotoPoint
    {
        public int X { get; set; }
        public int Y { get; set; }
        public double Width { get; set; }
        public double Height { get; set; }
        public int Angle { get; set; }
        public double DXFWidth { get; set; }
        public double DXFHeigth { get; set; }
        public byte[] DXFContent { get; set; }
        public string DxfPath { get; set; }
        public PhotoBarCodeLocal BarCodeLocal { get; set; }
    }
    /// <summary>
    /// 实现图片转换
    /// </summary>
    class TransferImage : AxHost
    {
        public TransferImage(string aa)
            : base(aa)
        {

        }
        public Image TransferPictureToImage(object obj)
        {
            return AxHost.GetPictureFromIPicture(obj);

        }


    }
}